From 05e1bcf4f1157f55f06403e1d5446c4d8e1f8655 Mon Sep 17 00:00:00 2001 From: Matthew Mongeau Date: Fri, 6 Jul 2012 17:13:53 -0400 Subject: [PATCH] workarounds for get_about_section --- common/lib/xmodule/xmodule/modulestore/xml.py | 4 +- lms/djangoapps/courseware/courses.py | 25 +++ lms/djangoapps/courseware/views.py | 9 +- lms/djangoapps/student/views.py | 5 +- lms/envs/common.py | 6 + lms/envs/dev.py | 2 +- lms/templates/course.html | 155 +----------------- lms/urls.py | 25 ++- 8 files changed, 63 insertions(+), 168 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index 3e6e54be45..d85b6d2cad 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -1,4 +1,5 @@ import logging +from django.conf import settings from fs.osfs import OSFS from importlib import import_module from lxml import etree @@ -128,7 +129,8 @@ class XMLModuleStore(ModuleStore): """ Returns a list of course descriptors """ - return self.courses + # return self.courses + return settings.COURSES def create_item(self, location): raise NotImplementedError("XMLModuleStores are read-only") diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 52be6a7cbd..43347f719d 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -27,6 +27,31 @@ class Course(namedtuple('Course', _FIELDS)): """Course objects encapsulate general information about a given run of a course. This includes things like name, grading policy, etc. """ + @property + def id(self): + return "{0.institution},{0.number},{0.run_id}".format(self).replace(" ", "_") + + def get_about_section(self, section): + if section == "university": + section = "institution" + if section in _FIELDS: + getattr(self, section) + else: + return section + + @classmethod + def load_from_path(cls, course_path): + course_path = path(course_path) # convert it from string if necessary + try: + with open(course_path / "course_info.yaml") as course_info_file: + course_info = yaml.load(course_info_file) + summary = course_info['course'] + summary.update(path=course_path, grader=None) + return cls(**summary) + except Exception as ex: + log.exception(ex) + raise CourseInfoLoadError("Could not read course info: {0}:{1}" + .format(type(ex).__name__, ex)) def load_courses(courses_path): """Given a directory of courses, returns a list of Course objects. For the diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 403a472d42..8dd278be55 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -54,7 +54,9 @@ def format_url_params(params): def courses(request): csrf_token = csrf(request)['csrf_token'] # TODO: Clean up how 'error' is done. - context = {'courses': modulestore().get_courses(), + # context = {'courses': modulestore().get_courses(), + # 'csrf': csrf_token} + context = {'courses': settings.COURSES, 'csrf': csrf_token} return render_to_response("courses.html", context) @@ -252,8 +254,9 @@ def course_info(request, course_id): csrf_token = csrf(request)['csrf_token'] try: - course_location = CourseDescriptor.id_to_location(course_id) - course = modulestore().get_item(course_location) + # course_location = CourseDescriptor.id_to_location(course_id) + # course = modulestore().get_item(course_location) + course = settings.COURSES_BY_ID[course_id] except KeyError: raise Http404("Course not found") diff --git a/lms/djangoapps/student/views.py b/lms/djangoapps/student/views.py index 3319b33207..06cd41dedc 100644 --- a/lms/djangoapps/student/views.py +++ b/lms/djangoapps/student/views.py @@ -491,8 +491,9 @@ def accept_name_change(request): def course_info(request, course_id): # This is the advertising page for a student to look at the course before signing up csrf_token = csrf(request)['csrf_token'] - course_loc = CourseDescriptor.id_to_location(course_id) - course = modulestore().get_item(course_loc) + # course_loc = CourseDescriptor.id_to_location(course_id) + # course = modulestore().get_item(course_loc) + course = settings.COURSES_BY_ID[course_id] # TODO: Couse should be a model return render_to_response('portal/course_about.html', {'csrf': csrf_token, 'course': course}) diff --git a/lms/envs/common.py b/lms/envs/common.py index 928aa2bd01..8a9530de09 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -64,6 +64,12 @@ sys.path.append(PROJECT_ROOT / 'lib') sys.path.append(COMMON_ROOT / 'djangoapps') sys.path.append(COMMON_ROOT / 'lib') +######### EDX dormsbee/portal changes ################# +from courseware.courses import create_lookup_table, load_courses +COURSES = load_courses(ENV_ROOT / "data") +COURSES_BY_ID = create_lookup_table(COURSES) +####################################################### + ################################## MITXWEB ##################################### # This is where we stick our compiled template files. Most of the app uses Mako # templates diff --git a/lms/envs/dev.py b/lms/envs/dev.py index f175ca1f53..decd92d136 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -11,7 +11,7 @@ from .common import * from .logsettings import get_logger_config DEBUG = True -TEMPLATE_DEBUG = False +TEMPLATE_DEBUG = True LOGGING = get_logger_config(ENV_ROOT / "log", logging_env="dev", diff --git a/lms/templates/course.html b/lms/templates/course.html index 35f9e46acf..3ae00f88a2 100644 --- a/lms/templates/course.html +++ b/lms/templates/course.html @@ -2,33 +2,7 @@ <%! from django.core.urlresolvers import reverse %> - -%for course in courses: -
-
-
- -
-

${course.title}

-
- -
-
-
-
-

${course.institution}

-

7/23/1212/15/12

-
-
- -
-
-

An advanced introduction to analog circuits.

-
-
-
-
-%endfor +<%page args="course"/>
@@ -46,132 +20,7 @@

7/23/1212/15/12

- -
-
-

An advanced introduction to analog circuits.

-
- - -
- -
-
-
- -
-

${course.title}

-
- -
-
-
-
-

${course.institution}

-

7/23/1212/15/12

-
-
- -
-
-

An advanced introduction to analog circuits.

-
-
-
-
- -
-
-
- -
-

${course.title}

-
- -
-
-
-
-

${course.institution}

-

7/23/1212/15/12

-
-
- -
-
-

An advanced introduction to analog circuits.

-
-
-
-
- -
-
-
- -
-

${course.title}

-
- -
-
-
-
-

${course.institution}

-

7/23/1212/15/12

-
-
- -
-
-

An advanced introduction to analog circuits.

-
-
-
-
- -
-
-
- -
-

${course.title}

-
- -
-
-
-
-

${course.institution}

-

7/23/1212/15/12

-
-
- -
-
-

An advanced introduction to analog circuits.

-
-
-
-
- -
-
-
- -
-

${course.title}

-
- -
-
-
-
-

${course.institution}

-

7/23/1212/15/12

-
-
- +

An advanced introduction to analog circuits.

diff --git a/lms/urls.py b/lms/urls.py index 0f3d78770e..9cb6a9483b 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -69,15 +69,24 @@ if settings.COURSEWARE_ENABLED: # Multicourse related: url(r'^courses/?$', 'courseware.views.courses', name="courses"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/info$', 'courseware.views.course_info', name="info"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/book$', 'staticbook.views.index', name="book"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/enroll$', 'student.views.enroll', name="enroll"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/courseware/?$', 'courseware.views.index', name="courseware"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/courseware/(?P[^/]*)/(?P
[^/]*)/$', 'courseware.views.index', name="courseware_section"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/profile$', 'courseware.views.profile', name="profile"), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/profile/(?P[^/]*)/$', 'courseware.views.profile'), + url(r'^courses/(?P[^/]*)/info$', 'courseware.views.course_info', name="info"), + url(r'^courses/(?P[^/]*)/book$', 'staticbook.views.index', name="book"), + url(r'^courses/(?P[^/]*)/enroll$', 'student.views.enroll', name="enroll"), + url(r'^courses/(?P[^/]*)/courseware/?$', 'courseware.views.index', name="courseware"), + url(r'^courses/(?P[^/]*)/courseware/(?P[^/]*)/(?P
[^/]*)/$', 'courseware.views.index', name="courseware_section"), + url(r'^courses/(?P[^/]*)/profile$', 'courseware.views.profile', name="profile"), + url(r'^courses/(?P[^/]*)/profile/(?P[^/]*)/$', 'courseware.views.profile'), - url(r'^courses/(?P[^/]+/[^/]+/[^/])/about$', 'courseware.views.course_info', name="about_course"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/info$', 'courseware.views.course_info', name="info"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/book$', 'staticbook.views.index', name="book"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/enroll$', 'student.views.enroll', name="enroll"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/courseware/?$', 'courseware.views.index', name="courseware"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/courseware/(?P[^/]*)/(?P
[^/]*)/$', 'courseware.views.index', name="courseware_section"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/profile$', 'courseware.views.profile', name="profile"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/profile/(?P[^/]*)/$', 'courseware.views.profile'), + + url(r'^courses/(?P[^/]*)/about$', 'student.views.course_info', name="about_course"), + # url(r'^courses/(?P[^/]+/[^/]+/[^/])/about$', 'courseware.views.course_info', name="about_course"), ) if settings.ENABLE_MULTICOURSE: