From bc8c077379223fdd22cb29b20e9a4037a7a2542d Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 20 Jun 2012 23:02:21 -0400 Subject: [PATCH] Add info page support with multiple courses --- common/djangoapps/util/views.py | 18 ++++++++++++++++-- lms/djangoapps/courseware/courses.py | 2 +- lms/envs/common.py | 3 ++- lms/templates/course.html | 2 ++ lms/templates/info.html | 8 ++++---- lms/templates/main.html | 2 +- lms/templates/navigation.html | 3 +++ lms/urls.py | 3 ++- 8 files changed, 31 insertions(+), 10 deletions(-) diff --git a/common/djangoapps/util/views.py b/common/djangoapps/util/views.py index c1f2bb39ea..132f6dfe5a 100644 --- a/common/djangoapps/util/views.py +++ b/common/djangoapps/util/views.py @@ -57,9 +57,23 @@ def send_feedback(request): ) return HttpResponse(json.dumps({'success':True})) -def info(request): +def info(request, course_id=None): ''' Info page (link from main header) ''' - return render_to_response("info.html", {}) + try: + course = settings.COURSES_BY_ID[course_id] + except KeyError: + raise Http404("Course not found") + + # We're bypassing the templating system for this part. We should cache + # this. + sections = ["updates", "handouts", "guest_updates", "guest_handouts"] + sections_to_content = {} + for section in sections: + filename = section + ".html" + with open(course.path / "info" / filename) as f: + sections_to_content[section] = f.read() + + return render_to_response("info.html", sections_to_content) # From http://djangosnippets.org/snippets/1042/ def parse_accept_header(accept): diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index fefb0f9c1e..7299dff068 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -29,7 +29,7 @@ class Course(namedtuple('Course', _FIELDS)): """ @property def id(self): - return "{0.institution},{0.number},{0.run_id}".format(self) + return "{0.institution},{0.number},{0.run_id}".format(self).replace(" ", "_") @classmethod def load_from_path(cls, course_path): diff --git a/lms/envs/common.py b/lms/envs/common.py index 7e985a691b..c2156d35ad 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -65,8 +65,9 @@ sys.path.append(COMMON_ROOT / 'djangoapps') sys.path.append(COMMON_ROOT / 'lib') ######### EDX dormsbee/portal changes ################# -from courseware.courses import load_courses +from courseware.courses import create_lookup_table, load_courses COURSES = load_courses(ENV_ROOT / "data") +COURSES_BY_ID = create_lookup_table(COURSES) ####################################################### ################################## MITXWEB ##################################### diff --git a/lms/templates/course.html b/lms/templates/course.html index 8841035186..4169e4ccfb 100644 --- a/lms/templates/course.html +++ b/lms/templates/course.html @@ -12,6 +12,7 @@

${course.title}

${",".join(course.instructors)} — ${course.institution}

+

${course.id}

Register
@@ -22,5 +23,6 @@
+

Hackish temp link to courseware

%endfor diff --git a/lms/templates/info.html b/lms/templates/info.html index 97bf413638..e09ec34ef2 100644 --- a/lms/templates/info.html +++ b/lms/templates/info.html @@ -7,17 +7,17 @@
% if user.is_authenticated():
- <%include file="updates.html" /> + ${updates}
- <%include file="handouts.html" /> + ${handouts}
% else:
- <%include file="guest_updates.html" /> + ${guest_updates}
- <%include file="guest_handouts.html" /> + ${guest_handouts}
% endif
diff --git a/lms/templates/main.html b/lms/templates/main.html index e34913b5c2..6ad0eb657b 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -2,7 +2,7 @@ - <%block name="title">MITx 6.002x + <%block name="title">edX diff --git a/lms/templates/navigation.html b/lms/templates/navigation.html index ff96583a2a..e4738349bc 100644 --- a/lms/templates/navigation.html +++ b/lms/templates/navigation.html @@ -1,3 +1,6 @@ +## TODO: Split this into two files, one for people who are authenticated, and +## one for people who aren't. Assume a Course object is passed to the former, +## instead of using settings.COURSE_TITLE <%namespace name='static' file='static_content.html'/>
diff --git a/lms/urls.py b/lms/urls.py index 021b730c42..15ea0ea4cb 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -50,7 +50,6 @@ if settings.PERFSTATS: if settings.COURSEWARE_ENABLED: urlpatterns += ( url(r'^courseware/$', 'courseware.views.index', name="courseware"), - url(r'^info$', 'util.views.info'), url(r'^wiki/', include('simplewiki.urls')), url(r'^masquerade/', include('masquerade.urls')), url(r'^courseware/(?P[^/]*)/(?P[^/]*)/(?P
[^/]*)/(?P[^/]*)$', 'courseware.views.index'), @@ -76,6 +75,8 @@ if settings.COURSEWARE_ENABLED: # Multicourse related: url(r'^courses$', 'courseware.views.courses'), + url(r'^courses/(?P[^/]*)/info$', 'util.views.info'), + ) if settings.ENABLE_MULTICOURSE: