-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added models for ES-ID document and ES-PostalCodes (#372)
- Loading branch information
1 parent
27b01b6
commit 2e27476
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from django.db.models import CharField | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from .forms import ESIdentityCardNumberField as ESIdentityCardNumberFormField | ||
from .forms import ESPostalCodeField as ESPostalCodeFormField | ||
|
||
|
||
class ESPostalCodeField(CharField): | ||
""" | ||
A model field that stores the five numbers (XXXXX) of Spain Postal Codes | ||
Forms represent it as ``form.ESPostalCodeField`` | ||
.. versionadded:: 2.2 | ||
""" | ||
|
||
description = _("Spain postal code ( five numbers)") | ||
|
||
def __init__(self, *args, **kwargs): | ||
kwargs['max_length'] = 5 | ||
super(ESPostalCodeField, self).__init__(*args, **kwargs) | ||
|
||
def formfield(self, **kwargs): | ||
defaults = {'form_class': ESPostalCodeFormField} | ||
defaults.update(kwargs) | ||
return super(ESPostalCodeField, self).formfield(**defaults) | ||
|
||
|
||
class ESIdentityCardNumberField(CharField): | ||
"""A model field that stores Spanish NIF/NIE/CIF in format ``XXXXXXXXX`` | ||
Forms represent it as ``form.ESIdentityCardNumberField`` field. | ||
.. versionadded:: 2.2 | ||
""" | ||
|
||
description = _("Identification National Document") | ||
|
||
def __init__(self, *args, **kwargs): | ||
kwargs['max_length'] = 9 | ||
super(ESIdentityCardNumberField, self).__init__(*args, **kwargs) | ||
|
||
def to_python(self, value): | ||
value = super(ESIdentityCardNumberField, self).to_python(value) | ||
if value is not None: | ||
return value.upper().replace(' ', '').replace('-', '') | ||
return value | ||
|
||
def formfield(self, **kwargs): | ||
defaults = {'form_class': ESIdentityCardNumberFormField} | ||
defaults.update(kwargs) | ||
return super(ESIdentityCardNumberField, self).formfield(**defaults) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters