Commit cdcf4099 authored by Skia's avatar Skia

Prevent loop in Wiki

parent 18115a0d
[{"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
......@@ -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()
......
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
......
# 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'}
......
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