| 1 | """ |
| 2 | # ESPostalCodeField ############################################################# |
| 3 | |
| 4 | ESPostalCodeField validates that the data is a valid ES postal code. |
| 5 | >>> from django.contrib.localflavor.es.forms import ESPostalCodeField |
| 6 | >>> f = ESPostalCodeField() |
| 7 | >>> f.clean('01000') |
| 8 | u'01000' |
| 9 | >>> f.clean('52999') |
| 10 | u'52999' |
| 11 | >>> f.clean('00999') |
| 12 | Traceback (most recent call last): |
| 13 | ... |
| 14 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 15 | >>> f.clean('53000') |
| 16 | Traceback (most recent call last): |
| 17 | ... |
| 18 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 19 | >>> f.clean('2A200') |
| 20 | Traceback (most recent call last): |
| 21 | ... |
| 22 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 23 | >>> f.clean('380001') |
| 24 | Traceback (most recent call last): |
| 25 | ... |
| 26 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 27 | >>> f.clean(None) |
| 28 | Traceback (most recent call last): |
| 29 | ... |
| 30 | ValidationError: [u'This field is required.'] |
| 31 | >>> f.clean('') |
| 32 | Traceback (most recent call last): |
| 33 | ... |
| 34 | ValidationError: [u'This field is required.'] |
| 35 | |
| 36 | >>> f = ESPostalCodeField(required=False) |
| 37 | >>> f.clean('01000') |
| 38 | u'01000' |
| 39 | >>> f.clean('52999') |
| 40 | u'52999' |
| 41 | >>> f.clean('00999') |
| 42 | Traceback (most recent call last): |
| 43 | ... |
| 44 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 45 | >>> f.clean('53000') |
| 46 | Traceback (most recent call last): |
| 47 | ... |
| 48 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 49 | >>> f.clean('2A200') |
| 50 | Traceback (most recent call last): |
| 51 | ... |
| 52 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 53 | >>> f.clean('380001') |
| 54 | Traceback (most recent call last): |
| 55 | ... |
| 56 | ValidationError: [u'Enter a valid postal code in the format XXXXX.'] |
| 57 | >>> f.clean(None) |
| 58 | u'' |
| 59 | >>> f.clean('') |
| 60 | u'' |
| 61 | |
| 62 | # ESSubdivisionSelect ############################################################### |
| 63 | |
| 64 | ESSubdivisionSelect |
| 65 | >>> from django.contrib.localflavor.es.forms import ESSubdivisionSelect |
| 66 | >>> w = ESSubdivisionSelect() |
| 67 | >>> w.render('provinces', 'TF') |
| 68 | u'<select name="provinces">\n<option value="VI">\xc1lava</option>\n<option value="AB">Albacete</option>\n<option value="A">Alicante</option>\n<option value="AL">Almer\xeda</option>\n<option value="O">Asturias</option>\n<option value="AV">\xc1vila</option>\n<option value="BA">Badajoz</option>\n<option value="PM">Islas Baleares</option>\n<option value="B">Barcelona</option>\n<option value="Bu">Burgos</option>\n<option value="CC">C\xe1ceres</option>\n<option value="CA">C\xe1diz</option>\n<option value="S">Cantabria</option>\n<option value="CS">Castell\xf3n</option>\n<option value="CE">Ceuta</option>\n<option value="CR">Ciudad Real</option>\n<option value="CO">C\xf3rdoba</option>\n<option value="Cu">Cuenca</option>\n<option value="GI">Gerona</option>\n<option value="GR">Granada</option>\n<option value="Gu">Guadalajara</option>\n<option value="SS">Guip\xfazcoa</option>\n<option value="H">Huelva</option>\n<option value="Hu">Huesca</option>\n<option value="J">Ja\xe9n</option>\n<option value="C">La Coru\xf1a</option>\n<option value="LO">La Rioja</option>\n<option value="GC">Las Palmas</option>\n<option value="LE">Le\xf3n</option>\n<option value="L">L\xe9rida</option>\n<option value="Lu">Lugo</option>\n<option value="M">Madrid</option>\n<option value="MA">M\xe1laga</option>\n<option value="ML">Melilla</option>\n<option value="Mu">Murcia</option>\n<option value="NA">Navarra</option>\n<option value="OR">Orense</option>\n<option value="P">Palencia</option>\n<option value="PO">Pontevedra</option>\n<option value="SA">Salamanca</option>\n<option value="TF" selected="selected">Santa Cruz de Tenerife</option>\n<option value="SG">Segovia</option>\n<option value="SE">Sevilla</option>\n<option value="SO">Soria</option>\n<option value="T">Tarragona</option>\n<option value="TE">Teruel</option>\n<option value="TO">Toledo</option>\n<option value="V">Valencia</option>\n<option value="VA">Valladolid</option>\n<option value="BI">Vizcaya</option>\n<option value="ZA">Zamora</option>\n<option value="Z">Zaragoza</option>\n</select>' |
| 69 | |
| 70 | # ESIdentityCardNumberField ############################################################# |
| 71 | |
| 72 | ESIdentityCardNumberField |
| 73 | >>> from django.contrib.localflavor.es.forms import ESIdentityCardNumberField |
| 74 | >>> f = ESIdentityCardNumberField() |
| 75 | >>> f.clean('78699688') |
| 76 | u'78699688J' |
| 77 | >>> f.clean('78699688J') |
| 78 | u'78699688J' |
| 79 | >>> f.clean('78699688-J') |
| 80 | u'78699688J' |
| 81 | >>> f.clean('78699688 J') |
| 82 | u'78699688J' |
| 83 | >>> f.clean('78699688 j') |
| 84 | u'78699688J' |
| 85 | >>> f.clean('78699688T') |
| 86 | Traceback (most recent call last): |
| 87 | ... |
| 88 | ValidationError: [u"The NIF you entered isn't valid. It should be 78699688J"] |
| 89 | >>> f.clean('X0901797J') |
| 90 | u'X0901797J' |
| 91 | >>> f.clean('X-6124387-Q') |
| 92 | u'X6124387Q' |
| 93 | >>> f.clean('X 0012953 G') |
| 94 | u'X0012953G' |
| 95 | >>> f.clean('x-3287690-r') |
| 96 | u'X3287690R' |
| 97 | >>> f.clean('X-03287690r') |
| 98 | u'X03287690R' |
| 99 | >>> f.clean('X-03287690') |
| 100 | u'X03287690R' |
| 101 | >>> f.clean('X-03287690-T') |
| 102 | Traceback (most recent call last): |
| 103 | ... |
| 104 | ValidationError: [u"The NIE you entered isn't valid. It should be X03287690R"] |
| 105 | >>> f.clean('B38790911') |
| 106 | u'B38790911' |
| 107 | >>> f.clean('B-3879091A') |
| 108 | Traceback (most recent call last): |
| 109 | ... |
| 110 | ValidationError: [u"The CIF you entered isn't valid. It should be B38790911"] |
| 111 | >>> f.clean('B 38790917') |
| 112 | Traceback (most recent call last): |
| 113 | ... |
| 114 | ValidationError: [u"The CIF you entered isn't valid. It should be B38790911"] |
| 115 | >>> f.clean('P-3900800-H') |
| 116 | u'P3900800H' |
| 117 | >>> f.clean('P 39008008') |
| 118 | Traceback (most recent call last): |
| 119 | ... |
| 120 | ValidationError: [u"The CIF you entered isn't valid. It should be P3900800H"] |
| 121 | >>> f.clean('C-28795565') |
| 122 | u'C28795565' |
| 123 | >>> f.clean('C 2879556E') |
| 124 | u'C2879556E' |
| 125 | >>> f.clean('C28795567') |
| 126 | Traceback (most recent call last): |
| 127 | ... |
| 128 | ValidationError: [u"The CIF you entered isn't valid. It should be C2879556E or C28795565"] |
| 129 | >>> f.clean('I38790911') |
| 130 | Traceback (most recent call last): |
| 131 | ... |
| 132 | ValidationError: [u"The CIF you entered isn't valid. It must start with A,B,C,D,E,F,G,H,K,L,M,N,P,Q or S"] |
| 133 | >>> f.clean('78699688-2') |
| 134 | Traceback (most recent call last): |
| 135 | ... |
| 136 | ValidationError: [u'Please, enter a valid CIF, NIF or NIE.'] |
| 137 | >>> f.clean('999999999') |
| 138 | Traceback (most recent call last): |
| 139 | ... |
| 140 | ValidationError: [u'Please, enter a valid CIF, NIF or NIE.'] |
| 141 | >>> f.clean(None) |
| 142 | Traceback (most recent call last): |
| 143 | ... |
| 144 | ValidationError: [u'This field is required.'] |
| 145 | >>> f.clean('') |
| 146 | Traceback (most recent call last): |
| 147 | ... |
| 148 | ValidationError: [u'This field is required.'] |
| 149 | >>> f = ESIdentityCardNumberField(required=False) |
| 150 | >>> f.clean(None) |
| 151 | u'' |
| 152 | >>> f.clean('') |
| 153 | u'' |
| 154 | >>> f = ESIdentityCardNumberField(show_correct=False) |
| 155 | >>> f.clean('78699688J') |
| 156 | u'78699688J' |
| 157 | >>> f.clean('78699688T') |
| 158 | Traceback (most recent call last): |
| 159 | ... |
| 160 | ValidationError: [u'Please, enter a valid NIF.'] |
| 161 | >>> f.clean('X-03287690-T') |
| 162 | Traceback (most recent call last): |
| 163 | ... |
| 164 | ValidationError: [u'Please, enter a valid NIE.'] |
| 165 | >>> f.clean('B-3879091A') |
| 166 | Traceback (most recent call last): |
| 167 | ... |
| 168 | ValidationError: [u'Please, enter a valid CIF.'] |
| 169 | >>> f.clean('P 39008008') |
| 170 | Traceback (most recent call last): |
| 171 | ... |
| 172 | ValidationError: [u'Please, enter a valid CIF.'] |
| 173 | >>> f.clean('C28795567') |
| 174 | Traceback (most recent call last): |
| 175 | ... |
| 176 | ValidationError: [u'Please, enter a valid CIF.'] |
| 177 | >>> f = ESIdentityCardNumberField(calc_control=False) |
| 178 | >>> f.clean('78699688J') |
| 179 | u'78699688J' |
| 180 | >>> f.clean('78699688') |
| 181 | Traceback (most recent call last): |
| 182 | ... |
| 183 | ValidationError: [u'Please, enter a valid NIF.'] |
| 184 | >>> f.clean('X-03287690') |
| 185 | Traceback (most recent call last): |
| 186 | ... |
| 187 | ValidationError: [u'Please, enter a valid NIE.'] |
| 188 | >>> f = ESIdentityCardNumberField(cif=False) |
| 189 | >>> f.clean('78699688J') |
| 190 | u'78699688J' |
| 191 | >>> f.clean('X-6124387-Q') |
| 192 | u'X6124387Q' |
| 193 | >>> f.clean('B38790911') |
| 194 | Traceback (most recent call last): |
| 195 | ... |
| 196 | ValidationError: [u'Please, enter a valid NIF or NIE.'] |
| 197 | >>> f = ESIdentityCardNumberField(nif=False) |
| 198 | >>> f.clean('78699688J') |
| 199 | Traceback (most recent call last): |
| 200 | ... |
| 201 | ValidationError: [u'Please, enter a valid CIF.'] |
| 202 | >>> f.clean('X-6124387-Q') |
| 203 | Traceback (most recent call last): |
| 204 | ... |
| 205 | ValidationError: [u'Please, enter a valid CIF.'] |
| 206 | >>> f.clean('B38790911') |
| 207 | u'B38790911' |
| 208 | """ |