Prevent loop in Wiki

This commit is contained in:
Skia 2015-11-24 20:09:44 +01:00
parent 18115a0dc4
commit cdcf4099fc
4 changed files with 20 additions and 6 deletions

View File

@ -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]}}]

View File

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

View File

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

View File

@ -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'}