mirror of https://github.com/django/django.git
Fixed #18234: Avoided exception on flatpage add
This commit is contained in:
parent
c2055ee161
commit
75743c189d
|
@ -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(
|
||||
|
|
|
@ -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.']})
|
||||
|
||||
|
|
Loading…
Reference in New Issue