Skip to content

Commit

Permalink
fix: Accept French Postal Services identifiers in forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Apr 22, 2024
1 parent a0bb1b5 commit 1baf78b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Authors
* Ben Konrath
* Bruno M. Custódio
* Burhan Khalid
* Célia Prat
* Claude Paroz
* Daniel Ampuero
* Daniela Ponader
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Modifications to existing flavors:

- Fix Belarus passport field description punctuation
(`gh-484 <https://github.com/django/django-localflavor/pull/484>`_).
- Accept French Postal Services identifiers in forms
(`gh-505 <https://github.com/django/django-localflavor/pull/505>`_).

Other changes:

Expand Down
3 changes: 2 additions & 1 deletion localflavor/fr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def clean(self, value):
return value

value = value.replace(' ', '').replace('-', '')
if not self.r_valid.match(value) or not luhn.is_valid(value):
if ((not self.r_valid.match(value) or not luhn.is_valid(value)) and not
(value.startswith("356000000") and sum(int(x) for x in value) % 5 == 0)):
raise ValidationError(self.error_messages['invalid'], code='invalid')
return value

Expand Down
2 changes: 2 additions & 0 deletions tests/test_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ def test_FRSIRENNumber(self):
'752932715': '752932715',
'752 932 715': '752932715',
'752-932-715': '752932715',
'35600000014597' : '35600000014597'
}
invalid = {
'1234': error_format, # wrong size
'752932712': error_format, # Bad luhn on SIREN
'35600000014596' : error_format
}
self.assertFieldOutput(FRSIRENField, valid, invalid)

Expand Down

0 comments on commit 1baf78b

Please sign in to comment.