Commit 1f43ae6d by Bridger Maxwell

Renamed namespace to wiki_slug in course_module.py.

parent 3dce1c28
...@@ -169,7 +169,7 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -169,7 +169,7 @@ class CourseDescriptor(SequenceDescriptor):
return self.location.course return self.location.course
@property @property
def wiki_namespace(self): def wiki_slug(self):
return self.location.course return self.location.course
@property @property
......
from django.shortcuts import redirect import logging
import re
from django.shortcuts import redirect
from wiki.core.exceptions import NoRootURL from wiki.core.exceptions import NoRootURL
from wiki.models import URLPath, Article from wiki.models import URLPath, Article
from courseware.courses import check_course from courseware.courses import check_course
log = logging.getLogger(__name__)
def root_create(request): def root_create(request):
""" """
...@@ -21,13 +25,23 @@ def course_wiki_redirect(request, course_id): ...@@ -21,13 +25,23 @@ def course_wiki_redirect(request, course_id):
as it's home page. A course's wiki must be an article on the root (for as it's home page. A course's wiki must be an article on the root (for
example, "/6.002x") to keep things simple. example, "/6.002x") to keep things simple.
""" """
course = check_course(course_id) course = check_course(request.user, course_id)
namespace = course.wiki_namespace course_slug = course.wiki_slug
valid_slug = True
#TODO: Make sure this is a legal slug. No "/"'s #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="")
try: try:
urlpath = URLPath.get_by_path(namespace, select_related=True) urlpath = URLPath.get_by_path(course_slug, select_related=True)
results = list( Article.objects.filter( id = urlpath.article.id ) ) results = list( Article.objects.filter( id = urlpath.article.id ) )
if results: if results:
...@@ -51,7 +65,7 @@ def course_wiki_redirect(request, course_id): ...@@ -51,7 +65,7 @@ def course_wiki_redirect(request, course_id):
urlpath = URLPath.create_article( urlpath = URLPath.create_article(
root, root,
namespace, course_slug,
title=course.title, title=course.title,
content="This is the wiki for " + course.title + ".", content="This is the wiki for " + course.title + ".",
user_message="Course page automatically created.", user_message="Course page automatically created.",
......
...@@ -44,4 +44,5 @@ django-ses ...@@ -44,4 +44,5 @@ django-ses
django-storages django-storages
django-threaded-multihost django-threaded-multihost
-e git+git://github.com/benjaoming/django-wiki.git#egg=django-wiki -e git+git://github.com/benjaoming/django-wiki.git#egg=django-wiki
django-sekizai<0.7
-r repo-requirements.txt -r repo-requirements.txt
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment