You can now click around in the wiki without losing your course nav bar.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from urlparse import urlparse
|
||||
|
||||
from django.http import Http404
|
||||
from django.shortcuts import redirect
|
||||
@@ -6,6 +7,44 @@ from django.shortcuts import redirect
|
||||
from courseware.courses import check_course
|
||||
|
||||
|
||||
class Middleware(object):
|
||||
"""
|
||||
This middleware is to keep the course nav bar above the wiki while
|
||||
the student clicks around to other wiki pages.
|
||||
If it intercepts a request for /wiki/.. that has a referrer in the
|
||||
form /courses/course_id/... it will redirect the user to the page
|
||||
/courses/course_id/wiki/...
|
||||
"""
|
||||
|
||||
def process_request(self, request):
|
||||
#TODO: We should also redirect people who can't see the class to the regular wiki, so urls don't break
|
||||
|
||||
referer = request.META.get('HTTP_REFERER')
|
||||
|
||||
try:
|
||||
parsed_referer = urlparse(referer)
|
||||
referer_path = parsed_referer.path
|
||||
except:
|
||||
referer_path =""
|
||||
|
||||
path_match = re.match(r'^/wiki/(?P<wiki_path>.*|)$', request.path)
|
||||
if path_match:
|
||||
# We are going to the wiki. Check if we came from a course
|
||||
course_match = re.match(r'/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/.*', referer_path)
|
||||
if course_match:
|
||||
course_id = course_match.group('course_id')
|
||||
|
||||
# See if we are able to view the course. If we are, redirect to it
|
||||
try:
|
||||
course = check_course(request.user, course_id)
|
||||
return redirect("/courses/" + course.id + "/view_wiki/" + path_match.group('wiki_path') )
|
||||
|
||||
except Http404:
|
||||
# Even though we came from the course, we can't see it. So don't worry about it.
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
def context_processor(request):
|
||||
"""
|
||||
This is a context processor which looks at the URL while we are
|
||||
@@ -15,7 +54,7 @@ def context_processor(request):
|
||||
bar to be shown.
|
||||
"""
|
||||
|
||||
match = re.match(r'^/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki(?P<wiki_path>.*|)', request.path)
|
||||
match = re.match(r'^/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/view_wiki(?P<wiki_path>.*|)', request.path)
|
||||
if match:
|
||||
course_id = match.group('course_id')
|
||||
|
||||
|
||||
@@ -328,6 +328,8 @@ MIDDLEWARE_CLASSES = (
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'track.middleware.TrackMiddleware',
|
||||
'mitxmako.middleware.MakoMiddleware',
|
||||
|
||||
'course_wiki.course_nav.Middleware',
|
||||
|
||||
'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
|
||||
'askbot.middleware.forum_mode.ForumModeMiddleware',
|
||||
|
||||
@@ -172,9 +172,9 @@ if settings.WIKI_ENABLED:
|
||||
|
||||
# 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<course_id>[^/]+/[^/]+/[^/]+)/wiki$',
|
||||
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki/?$',
|
||||
'course_wiki.views.course_wiki_redirect', name="course_wiki"),
|
||||
url(r'^courses/(?:[^/]+/[^/]+/[^/]+)/wiki/', include(wiki_pattern())),
|
||||
url(r'^courses/(?:[^/]+/[^/]+/[^/]+)/view_wiki/', include(wiki_pattern())),
|
||||
)
|
||||
|
||||
if settings.QUICKEDIT:
|
||||
|
||||
Reference in New Issue
Block a user