Fixed #18234: Avoided exception on flatpage add

This commit is contained in:
Karen Tracey 2012-04-28 19:44:14 -04:00
parent c2055ee161
commit 75743c189d
2 changed files with 14 additions and 1 deletions

View File

@ -31,7 +31,7 @@ class FlatpageForm(forms.ModelForm):
if self.instance.pk:
same_url = same_url.exclude(pk=self.instance.pk)
if same_url.filter(sites__in=sites).exists():
if sites and same_url.filter(sites__in=sites).exists():
for site in sites:
if same_url.filter(sites=site).exists():
raise forms.ValidationError(

View File

@ -78,3 +78,16 @@ class FlatpageAdminFormTests(TestCase):
updated = f.save()
self.assertEqual(updated.title, "A test page")
def test_flatpage_nosites(self):
data = dict(url='/myflatpage1/', **self.form_data)
data.update({'sites': ''})
f = FlatpageForm(data=data)
self.assertFalse(f.is_valid())
self.assertEqual(
f.errors,
{'sites': [u'This field is required.']})