Skip to content

Commit

Permalink
Add error messaging when user tries to create a duplicate hierarchy
Browse files Browse the repository at this point in the history
Helps address issue #120
  • Loading branch information
nikolas committed Jan 27, 2016
1 parent 4152c8d commit f09b159
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pagetree/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ class Meta:
model = Hierarchy
fields = ['name', 'base_url']

def clean(self):
cleaned_data = super(CloneHierarchyForm, self).clean()
name = cleaned_data.get('name')
base_url = cleaned_data.get('base_url')

if Hierarchy.objects.filter(name=name).count() > 0:
raise forms.ValidationError(
'There\'s already a hierarchy with the name: {}'.format(
name))

if Hierarchy.objects.filter(base_url=base_url).count() > 0:
raise forms.ValidationError(
'There\'s already a hierarchy with the base_url: {}'.format(
base_url))


MoveSectionForm = movenodeform_factory(
Section,
Expand Down

0 comments on commit f09b159

Please sign in to comment.