django-localflavor
django-localflavor copied to clipboard
fix: Accept French Postal Services identifiers in forms
This PR is intended to fix the following issue : https://github.com/django/django-localflavor/issues/504
The form validation in FRSIRENENumberMixin
is missing a special case from the SIRENE register.
The identifiers for Postal Services need a special validation process and are not currently validated.
Source (in french) : https://www.sirene.fr/static-resources/doc/lettres/lettre-16-novembre-2013.pdf
All Changes
-
[x] Add an entry to the docs/changelog.rst describing the change.
-
[x] Add an entry for your name in the docs/authors.rst file if it's not already there.
Sorry for the delay for reviewing, could you please add/complement a test for this?
Thanks for getting back to me @claudep, I have added the test cases :)
The exception only applies to SIRET, not to SIREN, so this update isn't correct. I think we should remove the mixin and use stdnum to validate both of the fields directly in the form class. This would add few lines of common code to both classes but it makes things clearer.
Any reason to turn this PR as a draft?
The exception only applies to SIRET, not to SIREN, so this update isn't correct. I think we should remove the mixin and use stdnum to validate both of the fields directly in the form class. This would add few lines of common code to both classes but it makes things clearer.
I have removed the mixin as suggested and revised validation for both SIRET and SIREN.
Reminder : the SIREN is included in the SIRET (9 first characters)
Validation :
- SIREN has 9 chars AND validates luhn algorithm
- SIRET has 14 chars AND validates luhn algorithm OR starts with "356000000" and the sum of the 14 characters is a multiple of 5
Sources :
Thanks!