Ticket #14308: forms.py

File forms.py, 1.5 KB (added by Andrés Torres, 14 years ago)

The same as above in the description.

Line 
1"""
2MX-specific Form helpers
3"""
4
5from django.forms.fields import RegexField
6
7
8class MXRFCField(RegexField):
9 """
10 A field that accepts a 'classic' Mexican RFC (Registro Federal de Contribuyentes).
11
12 More info about this: http://es.wikipedia.org/wiki/Registo_Federal_de_Contribuyentes_(M%C3%A9xico)
13 """
14 def __init__(self, *args, **kwargs):
15 super(MXRFCField, self).__init__(r'^[a-zA-Z]{3}[a-zA-Z\d]?(\d\d)(0[\d]{1}|1[0-2]{1})(0[\d]{1}|[1-2]{1}\d|3[0-1])[a-zA-Z\d]{3}$', *args, **kwargs)
16
17 def clean(self, value):
18 value = super(MXRFCField, self).clean(value)
19 return value.upper()
20
21
22class MXCURPField(RegexField):
23 """
24 A field that accepts a 'classic' Mexican CURP (Clave Unica de Registro de Poblacion).
25
26 More info about this: http://es.wikipedia.org/wiki/Clave_%C3%9Anica_de_Registro_de_Poblaci%C3%B3n_%28M%C3%A9xico%29
27 """
28 def __init__(self, *args, **kwargs):
29 super(MXCURPField, self).__init__(r'^[a-zA-Z]{4}(\d\d)(0[\d]{1}|1[0-2]{1})(0[\d]{1}|[1-2]{1}\d|3[0-1])([hmHM]{1})[a-zA-Z]{5}\d{2}$', *args, **kwargs)
30
31 def clean(self, value):
32 value = super(MXCURPField, self).clean(value)
33 return value.upper()
34
35
36class MXZIPCodeField(RegexField):
37 """
38 A field that accepts a 'classic' Mexican ZIP Code.
39
40 More info about this: http://es.wikipedia.org/wiki/C%C3%B3digo_postal_mexicano
41 """
42 def __init__(self, *args, **kwargs):
43 super(MXZIPCodeField, self).__init__(r'^(\d){5}$', *args, **kwargs)
44
45
46
Back to Top