Added views for automatic course article creation.
This commit is contained in:
0
lms/djangoapps/course_wiki/__init__.py
Normal file
0
lms/djangoapps/course_wiki/__init__.py
Normal file
92
lms/djangoapps/course_wiki/views.py
Normal file
92
lms/djangoapps/course_wiki/views.py
Normal file
@@ -0,0 +1,92 @@
|
||||
from django.shortcuts import redirect
|
||||
|
||||
from wiki.core.exceptions import NoRootURL
|
||||
from wiki.models import URLPath, Article
|
||||
|
||||
from courseware.courses import check_course
|
||||
|
||||
def root_create(request):
|
||||
|
||||
"""
|
||||
In the edX wiki, we don't show the root_create view. Instead, we
|
||||
just create the root automatically if it doesn't exist.
|
||||
"""
|
||||
root = get_or_create_root()
|
||||
return redirect('wiki:get', path=root.path)
|
||||
|
||||
|
||||
def course_wiki_redirect(request, course_id):
|
||||
"""
|
||||
This redirects to whatever page on the wiki that the course designates
|
||||
as it's home page. A course's wiki must be an article on the root (for
|
||||
example, "/6.002x") to keep things simple.
|
||||
"""
|
||||
course = check_course(course_id)
|
||||
|
||||
namespace = course.wiki_namespace
|
||||
#TODO: Make sure this is a legal slug. No "/"'s
|
||||
|
||||
try:
|
||||
urlpath = URLPath.get_by_path(namespace, select_related=True)
|
||||
|
||||
results = list( Article.objects.filter( id = urlpath.article.id ) )
|
||||
if results:
|
||||
article = results[0]
|
||||
else:
|
||||
article = None
|
||||
|
||||
except (NoRootURL, URLPath.DoesNotExist):
|
||||
# We will create it in the next block
|
||||
urlpath = None
|
||||
article = None
|
||||
|
||||
if not article:
|
||||
# create it
|
||||
root = get_or_create_root()
|
||||
|
||||
if urlpath:
|
||||
# Somehow we got a urlpath without an article. Just delete it and
|
||||
# recerate it.
|
||||
urlpath.delete()
|
||||
|
||||
urlpath = URLPath.create_article(
|
||||
root,
|
||||
namespace,
|
||||
title=course.title,
|
||||
content="This is the wiki for " + course.title + ".",
|
||||
user_message="Course page automatically created.",
|
||||
user=None,
|
||||
ip_address=None,
|
||||
article_kwargs={'owner': None,
|
||||
'group': None,
|
||||
'group_read': True,
|
||||
'group_write': True,
|
||||
'other_read': True,
|
||||
'other_write': True,
|
||||
})
|
||||
|
||||
return redirect("wiki:get", path=urlpath.path)
|
||||
|
||||
|
||||
def get_or_create_root():
|
||||
"""
|
||||
Returns the root article, or creates it if it doesn't exist.
|
||||
"""
|
||||
try:
|
||||
root = URLPath.root()
|
||||
if not root.article:
|
||||
root.delete()
|
||||
raise NoRootURL
|
||||
return root
|
||||
except NoRootURL:
|
||||
pass
|
||||
|
||||
starting_content = "\n".join((
|
||||
"Welcome to the edX Wiki",
|
||||
"===",
|
||||
"Visit a course wiki to add an article."))
|
||||
|
||||
root = URLPath.create_root(title="edX Wiki",
|
||||
content=starting_content)
|
||||
return root
|
||||
|
||||
@@ -530,6 +530,7 @@ INSTALLED_APPS = (
|
||||
|
||||
#For the wiki
|
||||
'wiki', # The new django-wiki from benjaoming
|
||||
'course_wiki', # Our customizations
|
||||
'django_notify',
|
||||
'mptt',
|
||||
'sekizai',
|
||||
|
||||
@@ -151,8 +151,12 @@ if settings.WIKI_ENABLED:
|
||||
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki/', include('simplewiki.urls')),
|
||||
# )
|
||||
urlpatterns += (
|
||||
|
||||
#url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/wiki/', include('simplewiki.urls')),
|
||||
# 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(r'wiki/', include(wiki_pattern())),
|
||||
url(r'^notify/', include(notify_pattern())),
|
||||
|
||||
Reference in New Issue
Block a user