Ticket #16110: geodjango_16110.diff
File geodjango_16110.diff, 2.2 KB (added by , 13 years ago) |
---|
-
django/contrib/gis/forms/fields.py
26 26 # defaults (e.g., allow None). 27 27 self.srid = kwargs.pop('srid', None) 28 28 self.geom_type = kwargs.pop('geom_type', 'GEOMETRY') 29 self.null = kwargs.pop('null', True) 29 self.null = kwargs.pop('null', True) # Never checked: stop passing this? 30 30 super(GeometryField, self).__init__(**kwargs) 31 31 32 32 def clean(self, value): … … 36 36 the value cannot be instantiated as a Geometry. 37 37 """ 38 38 if not value: 39 if self.null and not self.required: 40 # The geometry column allows NULL and is not required. 41 return None 42 else: 39 if self.required: 43 40 raise forms.ValidationError(self.error_messages['no_geom']) 41 else: 42 return None 44 43 45 44 # Trying to create a Geometry object from the form value. 46 45 try: -
django/contrib/gis/tests/test_geoforms.py
34 34 fld = forms.GeometryField() 35 35 self.assertRaises(forms.ValidationError, fld.clean, None) 36 36 37 # Still not allowed if `null=False`.38 fld = forms.GeometryField(required=False, null=False)39 self.assertRaises(forms.ValidationError, fld.clean, None)40 41 37 # This will clean None as a geometry (See #10660). 42 38 fld = forms.GeometryField(required=False) 43 39 self.assertEqual(None, fld.clean(None)) 44 40 41 # We used to check the underlying db_field's nullability 42 # and effectively override required=False. Don't do that anymore. 43 # See #16610. 44 fld = forms.GeometryField(required=False, null=False) 45 self.assertEqual(None, fld.clean(None)) 46 47 45 48 def test03_geom_type(self): 46 49 "Testing GeometryField's handling of different geometry types." 47 50 # By default, all geometry types are allowed.