From 85f1899cb64e8c4cda1a013fff7d664c5ae487c3 Mon Sep 17 00:00:00 2001 From: Bridger Maxwell Date: Tue, 14 Aug 2012 17:15:35 -0400 Subject: [PATCH] Wiki pages can now be viewed from the course URL and the course nav is shown. It doesn't follow the user yet. --- lms/djangoapps/course_wiki/course_nav.py | 32 ++++++++++++++++++++++++ lms/djangoapps/course_wiki/views.py | 4 +-- lms/envs/common.py | 1 + lms/templates/course_navigation.html | 7 +++++- lms/templates/wiki/base.html | 10 +++++++- lms/urls.py | 13 +++++++--- 6 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 lms/djangoapps/course_wiki/course_nav.py diff --git a/lms/djangoapps/course_wiki/course_nav.py b/lms/djangoapps/course_wiki/course_nav.py new file mode 100644 index 0000000000..4604e09ff9 --- /dev/null +++ b/lms/djangoapps/course_wiki/course_nav.py @@ -0,0 +1,32 @@ +import re + +from django.http import Http404 +from django.shortcuts import redirect + +from courseware.courses import check_course + + +def context_processor(request): + """ + This is a context processor which looks at the URL while we are + in the wiki. If the url is in the form + /courses/(course_id)/wiki/... + then we add 'course' to the context. This allows the course nav + bar to be shown. + """ + + match = re.match(r'^/courses/(?P[^/]+/[^/]+/[^/]+)/wiki(?P.*|)', request.path) + if match: + course_id = match.group('course_id') + + try: + course = check_course(request.user, course_id) + return {'course' : course} + except Http404: + # We couldn't access the course for whatever reason. It is too late to change + # the URL here, so we just leave the course context. The middleware shouldn't + # let this happen + pass + + return {} + \ No newline at end of file diff --git a/lms/djangoapps/course_wiki/views.py b/lms/djangoapps/course_wiki/views.py index 83e726e49f..0ec69c5c3b 100644 --- a/lms/djangoapps/course_wiki/views.py +++ b/lms/djangoapps/course_wiki/views.py @@ -28,15 +28,15 @@ def course_wiki_redirect(request, course_id): course = check_course(request.user, course_id) course_slug = course.wiki_slug + valid_slug = True - #TODO: Make sure this is a legal slug. No "/"'s if not course_slug: log.exception("This course is improperly configured. The slug cannot be empty.") valid_slug = False if re.match('^[-\w\.]+$', course_slug) == None: log.exception("This course is improperly configured. The slug can only contain letters, numbers, periods or hyphens.") valid_slug = False - + if not valid_slug: return redirect("wiki:get", path="") diff --git a/lms/envs/common.py b/lms/envs/common.py index a611281f2e..e202f30498 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -132,6 +132,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'sekizai.context_processors.sekizai', + 'course_wiki.course_nav.context_processor', ) diff --git a/lms/templates/course_navigation.html b/lms/templates/course_navigation.html index 11ec0a6690..a9ee199774 100644 --- a/lms/templates/course_navigation.html +++ b/lms/templates/course_navigation.html @@ -1,6 +1,11 @@ -<%page args="active_page" /> +## mako +<%page args="active_page=None" /> <% +if active_page == None and active_page_context is not UNDEFINED: + # If active_page is not passed in as an argument, it may be in the context as active_page_context + active_page = active_page_context + def url_class(url): if url == active_page: return "active" diff --git a/lms/templates/wiki/base.html b/lms/templates/wiki/base.html index 93558939c4..3bfc8cd2aa 100644 --- a/lms/templates/wiki/base.html +++ b/lms/templates/wiki/base.html @@ -1,9 +1,17 @@ {% extends "main_django.html" %} -{% load sekizai_tags i18n %}{% load url from future %} +{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %} {% block title %}{% block pagetitle %}{% endblock %} | edX Wiki{% endblock %} +{% block headextra %} + {% compressed_css 'course' %} +{% endblock %} + {% block body %} + {% if course %} + {% include "course_navigation.html" with active_page_context="wiki" %} + {% endif %} + {% block wiki_body %} {% if messages %} diff --git a/lms/urls.py b/lms/urls.py index d6a6bcb10e..175cb9b25f 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -159,15 +159,22 @@ if settings.WIKI_ENABLED: from wiki.urls import get_pattern as wiki_pattern from django_notify.urls import get_pattern as notify_pattern + # Note that some of these urls are repeated in course_wiki.course_nav. Make sure to update + # them together. urlpatterns += ( # First we include views from course_wiki that we use to override the default views. # They come first in the urlpatterns so they get resolved first - url('^wiki/create-root/$', 'course_wiki.views.root_create', name='root_create'), - url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/wiki$', - 'course_wiki.views.course_wiki_redirect', name="course_wiki"), + url('^wiki/create-root/$', 'course_wiki.views.root_create', name='root_create'), + url(r'^wiki/', include(wiki_pattern())), url(r'^notify/', include(notify_pattern())), + + # These urls are for viewing the wiki in the context of a course. They should + # never be returned by a reverse() so they come after the other url patterns + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/wiki$', + 'course_wiki.views.course_wiki_redirect', name="course_wiki"), + url(r'^courses/(?:[^/]+/[^/]+/[^/]+)/wiki/', include(wiki_pattern())), ) if settings.QUICKEDIT: