Skip to content

Commit

Permalink
Fix empty value with (Zones) completers
Browse files Browse the repository at this point in the history
  • Loading branch information
noirbizarre committed May 29, 2015
1 parent 88ff750 commit 97976dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion udata/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def process_formdata(self, valuelist):
if len(valuelist) > 1:
oids = [clean_oid(id, self.model) for id in valuelist]
elif isinstance(valuelist[0], basestring):
oids = [clean_oid(id, self.model) for id in valuelist[0].split(',')]
oids = [clean_oid(id, self.model) for id in valuelist[0].split(',') if id]
else:
raise validators.ValidationError('Unsupported form parameter: ' + valuelist)

Expand Down
16 changes: 16 additions & 0 deletions udata/tests/forms/test_zones_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ def test_initial_values(self):
form = FakeForm(None, fake)
self.assertEqual(form.spatial.zones._value(), ','.join([z.id for z in zones]))

def test_with_zone_empty_string(self):
Fake, FakeForm = self.factory()

fake = Fake()
form = FakeForm(MultiDict({
'spatial-zones': '',
'spatial-granularity': random_spatial_granularity()
}))

form.validate()
self.assertEqual(form.errors, {})

form.populate_obj(fake)

self.assertEqual(len(fake.spatial.zones), 0)

def test_with_valid_zone(self):
Fake, FakeForm = self.factory()
zone = GeoZoneFactory()
Expand Down

0 comments on commit 97976dc

Please sign in to comment.