equal
deleted
inserted
replaced
1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 """ |
2 """ |
3 AR-specific Form helpers. |
3 AR-specific Form helpers. |
4 """ |
4 """ |
5 |
5 |
6 from django.newforms import ValidationError |
6 from django.forms import ValidationError |
7 from django.newforms.fields import RegexField, CharField, Select, EMPTY_VALUES |
7 from django.forms.fields import RegexField, CharField, Select, EMPTY_VALUES |
8 from django.utils.encoding import smart_unicode |
8 from django.utils.encoding import smart_unicode |
9 from django.utils.translation import ugettext |
9 from django.utils.translation import ugettext_lazy as _ |
10 |
10 |
11 class ARProvinceSelect(Select): |
11 class ARProvinceSelect(Select): |
12 """ |
12 """ |
13 A Select widget that uses a list of Argentinean provinces/autonomous cities |
13 A Select widget that uses a list of Argentinean provinces/autonomous cities |
14 as its choices. |
14 as its choices. |
22 A field that accepts a 'classic' NNNN Postal Code or a CPA. |
22 A field that accepts a 'classic' NNNN Postal Code or a CPA. |
23 |
23 |
24 See http://www.correoargentino.com.ar/consulta_cpa/home.php |
24 See http://www.correoargentino.com.ar/consulta_cpa/home.php |
25 """ |
25 """ |
26 default_error_messages = { |
26 default_error_messages = { |
27 'invalid': ugettext("Enter a postal code in the format NNNN or ANNNNAAA."), |
27 'invalid': _("Enter a postal code in the format NNNN or ANNNNAAA."), |
28 } |
28 } |
29 |
29 |
30 def __init__(self, *args, **kwargs): |
30 def __init__(self, *args, **kwargs): |
31 super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$', |
31 super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$', |
32 min_length=4, max_length=8, *args, **kwargs) |
32 min_length=4, max_length=8, *args, **kwargs) |
44 class ARDNIField(CharField): |
44 class ARDNIField(CharField): |
45 """ |
45 """ |
46 A field that validates 'Documento Nacional de Identidad' (DNI) numbers. |
46 A field that validates 'Documento Nacional de Identidad' (DNI) numbers. |
47 """ |
47 """ |
48 default_error_messages = { |
48 default_error_messages = { |
49 'invalid': ugettext("This field requires only numbers."), |
49 'invalid': _("This field requires only numbers."), |
50 'max_digits': ugettext("This field requires 7 or 8 digits."), |
50 'max_digits': _("This field requires 7 or 8 digits."), |
51 } |
51 } |
52 |
52 |
53 def __init__(self, *args, **kwargs): |
53 def __init__(self, *args, **kwargs): |
54 super(ARDNIField, self).__init__(max_length=10, min_length=7, *args, |
54 super(ARDNIField, self).__init__(max_length=10, min_length=7, *args, |
55 **kwargs) |
55 **kwargs) |
74 """ |
74 """ |
75 This field validates a CUIT (Código Único de Identificación Tributaria). A |
75 This field validates a CUIT (Código Único de Identificación Tributaria). A |
76 CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit. |
76 CUIT is of the form XX-XXXXXXXX-V. The last digit is a check digit. |
77 """ |
77 """ |
78 default_error_messages = { |
78 default_error_messages = { |
79 'invalid': ugettext('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'), |
79 'invalid': _('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'), |
80 'checksum': ugettext("Invalid CUIT."), |
80 'checksum': _("Invalid CUIT."), |
81 } |
81 } |
82 |
82 |
83 def __init__(self, *args, **kwargs): |
83 def __init__(self, *args, **kwargs): |
84 super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$', |
84 super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$', |
85 *args, **kwargs) |
85 *args, **kwargs) |