Skip to content

Commit

Permalink
Fix saving a single space for empty postcode value. (#280)
Browse files Browse the repository at this point in the history
This also applies the `len(value)` logic found in the
formfield `NLZipCodeField.clean()` to be more robust.
  • Loading branch information
vdboor authored and benkonrath committed Mar 6, 2017
1 parent 08f6f7a commit 27454bd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Authors
* Daniela Ponader
* Danielle Madeley
* Daniel Roschka
* Diederik van der Boor
* d.merc
* Douglas Miranda
* Elliott Fawcett
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Modifications to existing flavors:

- Added normalized versions of COFA state names for US.
(`gh-277 <https://github.com/django/django-localflavor/pull/277>`_)
- Fixed Dutch NLZipCodeField field not to store empty value as a single space.
(`gh-280 <https://github.com/django/django-localflavor/pull/280>`_)

Other changes:

Expand Down
5 changes: 3 additions & 2 deletions localflavor/nl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def __init__(self, *args, **kwargs):

def to_python(self, value):
value = super(NLZipCodeField, self).to_python(value)
if value is not None:
if value:
value = value.upper().replace(' ', '')
return '%s %s' % (value[:4], value[4:])
if len(value) == 6:
return '%s %s' % (value[:4], value[4:])
return value

def formfield(self, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions tests/test_nl/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_NLZipCodeField(self):

self.assertEqual(field.to_python('1234AB'), '1234 AB')
self.assertEqual(field.to_python(None), None)
self.assertEqual(field.to_python(''), '')

self.assertIsInstance(field.formfield(), forms.NLZipCodeField)

Expand Down

0 comments on commit 27454bd

Please sign in to comment.