Commit 953cab04 by Bridger Maxwell

Added check that namespace for a new course is created.

parent 6f250fc0
......@@ -17,8 +17,18 @@ class ShouldHaveExactlyOneRootSlug(Exception):
pass
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
@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):
"""Wiki article referring to Revision model for actual content.
......
......@@ -88,7 +88,11 @@ def root_redirect(request, course_id):
try:
root = Article.get_root(course.wiki_namespace)
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 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