Skip to content

Commit

Permalink
Added checks for 'slug' key in cleaned_data to avoid errors during pa…
Browse files Browse the repository at this point in the history
…ge validation
  • Loading branch information
yakky committed Oct 18, 2012
1 parent 1851361 commit 85b5567
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cms/admin/forms.py
Expand Up @@ -92,7 +92,7 @@ def __init__(self, *args, **kwargs):

def clean(self):
cleaned_data = self.cleaned_data
if 'slug' in cleaned_data.keys():
if 'slug' in cleaned_data:
slug = cleaned_data['slug']
else:
slug = ""
Expand Down Expand Up @@ -121,17 +121,18 @@ def clean(self):
#AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
#Looks like just a theoretical corner case
title = page.get_title_obj(lang)
if title:
if title and slug:
oldslug = title.slug
title.slug = self.cleaned_data['slug']
title.slug = slug
title.save()
try:
is_valid_url(title.path,page)
except ValidationError,e:
title.slug = oldslug
title.save()
del cleaned_data['published']
self._errors['published'] = ErrorList(e.messages)
if 'slug' in cleaned_data:
del cleaned_data['slug']
self._errors['slug'] = ErrorList(e.messages)
return cleaned_data

def clean_slug(self):
Expand Down

0 comments on commit 85b5567

Please sign in to comment.