Skip to content

Commit e391e40

Browse files
thorbenkonrath
authored andcommitted
Fixes NOBankAccountNumber issue with formatting
If you would input accounts that were too short or otherwise riddled with spaces and periods, it would not remove these before showing them again. Fixes the issue and adds a couple of assertions.
1 parent ee0cabf commit e391e40

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

docs/changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Changelog
44
1.5.3 (unreleased)
55
--------------------
66

7+
Modifications to existing flavors:
8+
9+
- Fixes issue with `no.forms.NOBankAccountNumber` unclean data.
10+
(`gh-311 <https://github.com/django/django-localflavor/pull/311>`_).
11+
712
Other changes:
813

914
- None

localflavor/no/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def to_python(self, value):
160160
return value.replace('.', '').replace(' ', '')
161161

162162
def prepare_value(self, value):
163+
value = self.to_python(value)
163164
if value in self.empty_values:
164165
return self.empty_value
165166
return '{}.{}.{}'.format(value[0:4], value[4:6], value[6:11])

tests/test_no.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def test_NOBankAccountNumber(self):
6767
def test_NOBankAccountNumber_formatting(self):
6868
form = NOBankAccountNumber()
6969
self.assertEqual(form.prepare_value('76940512057'), '7694.05.12057')
70+
self.assertEqual(form.prepare_value(' 7694 05 12057 '), '7694.05.12057')
71+
self.assertEqual(form.prepare_value('7694. 05.1205'), '7694.05.1205')
72+
self.assertEqual(form.prepare_value('7694.05.120.5'), '7694.05.1205')
7073
# In the event there's already empty/blank/null values present.
7174
# Any invalid data should be stopped by form.validate, which the above test should take care of.
7275
self.assertEqual(form.prepare_value(None), '')

0 commit comments

Comments
 (0)