diff --git a/core/fixtures/groups.json b/core/fixtures/groups.json new file mode 100644 index 00000000..8ac77e46 --- /dev/null +++ b/core/fixtures/groups.json @@ -0,0 +1 @@ +[{"pk": 1, "model": "auth.group", "fields": {"name": "root", "permissions": [1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12, 19, 20, 21, 16, 17, 18, 13, 14, 15]}}] \ No newline at end of file diff --git a/core/models.py b/core/models.py index 49a19960..d095123b 100644 --- a/core/models.py +++ b/core/models.py @@ -174,6 +174,21 @@ class Page(models.Model): code='duplicate', ) super(Page, self).clean() + if self.parent is not None and self in self.get_parent_list(): + raise ValidationError( + _('Loop in page tree'), + code='loop', + ) + + def get_parent_list(self): + l = [] + p = self.parent + while p is not None: + l.append(p) + p = p.parent + return l + + def save(self, *args, **kwargs): self.full_clean() diff --git a/core/views/site.py b/core/views/site.py index d0c94464..7f237928 100644 --- a/core/views/site.py +++ b/core/views/site.py @@ -1,11 +1,6 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.http import HttpResponse -from django.contrib.auth import logout as auth_logout from django.db import models -from django.contrib.auth.forms import PasswordChangeForm - -from core.models import User, Page -from core.views.forms import RegisteringForm, LoginForm, UserEditForm, PageEditForm, PagePropForm import logging diff --git a/core/views/user.py b/core/views/user.py index a915759d..007eb844 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -1,8 +1,11 @@ # This file contains all the views that concern the user model from django.shortcuts import render, redirect, get_object_or_404 +from django.contrib.auth import logout as auth_logout +from django.contrib.auth.forms import PasswordChangeForm import logging -from core.views.forms import RegisteringForm, LoginForm +from core.views.forms import RegisteringForm, LoginForm, UserEditForm +from core.models import User def register(request): context = {'title': 'Register a user'}