1 6 10 12 14 15 16 18 19 20 21 23 24 25 27 28 29 30 32 33 34 35 36 39 44 47 49 50 54 56 57 58 59 60 61 64 65 66 67 68 69 70 71 72 73 74 75 77 78 79 80 81 83 84 85 |
# -*- coding: utf-8 -*-
"""Form for page creation""" label=_('Title'), widget=forms.TextInput(), ) label=_('Slug'), widget=forms.TextInput(), help_text=_('The slug will be used to create the page URL, it must be unique among the other pages of the same level.') ) label=_('Language'), choices=settings.PAGE_LANGUAGES, ) required=False, label=_('Template'), choices=settings.PAGE_TEMPLATES, ) required=False, label=_('Delegate to application'), choices=get_choices(), )
"""Handle move action on the pages"""
if self.instance.id: if Content.objects.exclude(page=self.instance).filter(body=slug, type="slug").count(): raise forms.ValidationError(_('Another page with this slug already exists')) elif Content.objects.filter(body=slug, type="slug").count(): raise forms.ValidationError(_('Another page with this slug already exists'))
target = Page.objects.get(pk=target) if position in ['right', 'left']: slugs = [sibling.slug() for sibling in target.get_siblings()] slugs.append(target.slug()) if slug in slugs: raise forms.ValidationError( _('A sibiling with this slug already exists at the targeted position')) if position == 'first-child': if slug in [sibling.slug() for sibling in target.get_children()]: raise forms.ValidationError( _('A child with this slug already exists at the targeted position')) else: if (slug in [sibling.slug() for sibling in self.instance.get_siblings().exclude(id=self.instance.id)]): raise forms.ValidationError( _('A sibiling with this slug already exists')) else: raise forms.ValidationError( _('A sibiling with this slug already exists at the root level')) return slug |