Added check that namespace for a new course is created.

This commit is contained in:
Bridger Maxwell
2012-07-05 08:55:35 -07:00
parent 6f250fc0d3
commit 953cab047a
2 changed files with 16 additions and 2 deletions

View File

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

View File

@@ -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()} ))