Ticket #17614: models.py.patch

File models.py.patch, 2.7 KB (added by croldan, 4 years ago)
  • django/contrib/localflavor/ar/models.py

     
     1from django.utils.translation import ugettext_lazy as _
     2from django.db.models.fields import CharField
     3from django.contrib.localflavor.ar.ar_provinces import PROVINCE_CHOICES
     4
     5class ARProvinceField(CharField):
     6    """
     7    A model field that stores the one-letter Argentinian province abbreviation
     8    in the database.
     9    """   
     10   
     11    description = _("Argentina province (one uppercase letter)")
     12   
     13    def __init__(self, *args, **kwargs):
     14        kwargs['choices'] = PROVINCE_CHOICES
     15        kwargs['max_length'] = 1
     16        super(ARProvinceField, self).__init__(*args, **kwargs)
     17
     18
     19class ARPostalCodeField(CharField):
     20    """
     21    A model field that forms represent as a forms.ARPostalCodeField field and
     22    stores the four-digit Argentinian postal code or an eight-digit CPA.
     23    """
     24    description = _("Argentinian postal code or CPA")
     25
     26    def __init__(self, *args, **kwargs):
     27        kwargs['max_length'] = 8
     28        super(ARPostalCodeField, self).__init__(*args, **kwargs)
     29
     30    def formfield(self, **kwargs):
     31        from forms import ARPostalCodeField as ARPostalCodeFormField
     32        defaults = {'form_class': ARPostalCodeFormField}
     33        defaults.update(kwargs)
     34        return super(ARPostalCodeField, self).formfield(**defaults)
     35
     36
     37class ARDNIField(CharField):
     38    """
     39    A model field that forms represent as a forms.ARDNIField field and
     40    stores the eight-digit Argentinian DNI.
     41    """
     42    description = _("Argentinian DNI")
     43
     44    def __init__(self, *args, **kwargs):
     45        kwargs['max_length'] = 8
     46        super(ARDNIField, self).__init__(*args, **kwargs)
     47
     48    def formfield(self, **kwargs):
     49        from forms import ARDNIField as ARDNIFormField
     50        defaults = {'form_class': ARDNIFormField}
     51        defaults.update(kwargs)
     52        return super(ARDNIField, self).formfield(**defaults)
     53
     54
     55class ARCUITField(CharField):
     56    """
     57    A model field that forms represent as a forms.ARCUITField field and
     58    stores the Argentinian CUIT/CUIL.
     59    """
     60    description = _("Argentinian CUIT/CUIL")
     61
     62    def __init__(self, *args, **kwargs):
     63        kwargs['max_length'] = 13
     64        super(ARCUITField, self).__init__(*args, **kwargs)
     65
     66    def formfield(self, **kwargs):
     67        from forms import ARCUITField as ARCUITFormField
     68        defaults = {'form_class': ARCUITFormField}
     69        defaults.update(kwargs)
     70        return super(ARCUITField, self).formfield(**defaults)
Back to Top