Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18234: Avoided exception on flatpage add

  • Loading branch information...
commit 75743c189d5138e47fd139b154c42e3bb67361c8 1 parent c2055ee
Karen Tracey authored April 28, 2012
2  django/contrib/flatpages/forms.py
@@ -31,7 +31,7 @@ def clean(self):
31 31
         if self.instance.pk:
32 32
             same_url = same_url.exclude(pk=self.instance.pk)
33 33
 
34  
-        if same_url.filter(sites__in=sites).exists():
  34
+        if sites and same_url.filter(sites__in=sites).exists():
35 35
             for site in sites:
36 36
                 if same_url.filter(sites=site).exists():
37 37
                     raise forms.ValidationError(
13  django/contrib/flatpages/tests/forms.py
@@ -78,3 +78,16 @@ def test_flatpage_admin_form_edit(self):
78 78
         updated = f.save()
79 79
 
80 80
         self.assertEqual(updated.title, "A test page")
  81
+
  82
+    def test_flatpage_nosites(self):
  83
+        data = dict(url='/myflatpage1/', **self.form_data)
  84
+        data.update({'sites': ''})
  85
+
  86
+        f = FlatpageForm(data=data)
  87
+
  88
+        self.assertFalse(f.is_valid())
  89
+
  90
+        self.assertEqual(
  91
+            f.errors,
  92
+            {'sites': [u'This field is required.']})
  93
+

0 notes on commit 75743c1

Please sign in to comment.
Something went wrong with that request. Please try again.