Commit 953cab04 by Bridger Maxwell

Added check that namespace for a new course is created.

parent 6f250fc0
...@@ -17,9 +17,19 @@ class ShouldHaveExactlyOneRootSlug(Exception): ...@@ -17,9 +17,19 @@ class ShouldHaveExactlyOneRootSlug(Exception):
pass pass
class Namespace(models.Model): class Namespace(models.Model):
name = models.CharField(max_length=30, verbose_name=_('namespace')) name = models.CharField(max_length=30, db_index=True, unique=True, verbose_name=_('namespace'))
# TODO: We may want to add permissions, etc later # TODO: We may want to add permissions, etc later
@classmethod
def ensure_namespace(cls, name):
try:
namespace = Namespace.objects.get(name__exact = name)
except Namespace.DoesNotExist:
new_namespace = Namespace(name=name)
new_namespace.save()
class Article(models.Model): class Article(models.Model):
"""Wiki article referring to Revision model for actual content. """Wiki article referring to Revision model for actual content.
'slug' and 'title' field should be maintained centrally, since users 'slug' and 'title' field should be maintained centrally, since users
......
...@@ -88,7 +88,11 @@ def root_redirect(request, course_id): ...@@ -88,7 +88,11 @@ def root_redirect(request, course_id):
try: try:
root = Article.get_root(course.wiki_namespace) root = Article.get_root(course.wiki_namespace)
except: except:
err = not_found(request, '/') # If the root is not found, we probably are loading this class for the first time
# We should make sure the namespace exists so the root article can be created.
Namespace.ensure_namespace(course.wiki_namespace)
err = not_found(request, course.wiki_namespace + '/', course)
return err return err
return HttpResponseRedirect(reverse('wiki_view', kwargs={'course_id' : course_id, 'article_path' : root.get_path()} )) return HttpResponseRedirect(reverse('wiki_view', kwargs={'course_id' : course_id, 'article_path' : root.get_path()} ))
......
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