Wiki pages can now be viewed from the course URL and the course nav is shown. It doesn't follow the user yet.

This commit is contained in:
Bridger Maxwell
2012-08-14 17:15:35 -04:00
parent 1f43ae6d3e
commit 85f1899cb6
6 changed files with 60 additions and 7 deletions

View File

@@ -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<course_id>[^/]+/[^/]+/[^/]+)/wiki(?P<wiki_path>.*|)', 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 {}

View File

@@ -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="")

View File

@@ -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',
)

View File

@@ -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"

View File

@@ -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 %}<title>{% block pagetitle %}{% endblock %} | edX Wiki</title>{% 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 %}

View File

@@ -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<course_id>[^/]+/[^/]+/[^/]+)/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<course_id>[^/]+/[^/]+/[^/]+)/wiki$',
'course_wiki.views.course_wiki_redirect', name="course_wiki"),
url(r'^courses/(?:[^/]+/[^/]+/[^/]+)/wiki/', include(wiki_pattern())),
)
if settings.QUICKEDIT: