Commits

funkybob  committed 319a0ac

Don't allow circular paths in pages

  • Participants
  • Parent commits c4ca9a5

Comments (0)

Files changed (2)

File gnocchi/cms/admin.py

 from django.contrib import admin
-from gnocchi.cms import settings, models
+from gnocchi.cms import settings, models, forms
 from gnocchi.tools.admin import InlineAttributeAdmin
 
 import os.path
     list_filter = ('parent', 'is_published',)
     list_editable = ('is_published',)
 
+    form = forms.PageAdminForm
+
     class Media:
         js = (
             'ckeditor/ckeditor.js',

File gnocchi/cms/forms.py

+from django import forms
+from gnocchi.cms import models
+
+class PageAdminForm(forms.ModelForm):
+
+    class Meta:
+        model = models.Page
+
+    def clean(self):
+        data = self.cleaned_data
+        if self.instance.pk:
+            visited = set(self.instance)
+            p = data['parent']
+            while p:
+                if p in visited:
+                    raise forms.ValidationError("Page path is circular!")
+                visited.add(p)
+                p = p.parent
+        return data