Django

Code

root/django/trunk/docs/localflavor.txt

Revision 7294, 17.9 kB (checked in by mtredinnick, 4 months ago)

Added "svn:eol-style native" to every text file in the tree (*.txt, *.html,
*.py, *.xml and AUTHORS, etc). Added "svn:ignore *.pyc" to some directories in
tests/regressiontests/ that were previously missing it.

Fixed #6545, #6801.

  • Property svn:eol-style set to native
Line 
1 ==========================
2 The "local flavor" add-ons
3 ==========================
4
5 Following its "batteries included" philosophy, Django comes with assorted
6 pieces of code that are useful for particular countries or cultures. These are
7 called the "local flavor" add-ons and live in the ``django.contrib.localflavor``
8 package.
9
10 Inside that package, country- or culture-specific code is organized into
11 subpackages, named using `ISO 3166 country codes`_.
12
13 Most of the ``localflavor`` add-ons are localized form components deriving from
14 the newforms_ framework -- for example, a ``USStateField`` that knows how to
15 validate U.S. state abbreviations, and a ``FISocialSecurityNumber`` that knows
16 how to validate Finnish social security numbers.
17
18 To use one of these localized components, just import the relevant subpackage.
19 For example, here's how you can create a form with a field representing a
20 French telephone number::
21
22     from django import newforms as forms
23     from django.contrib.localflavor import fr
24
25     class MyForm(forms.Form):
26         my_french_phone_no = fr.forms.FRPhoneNumberField()
27
28 Supported countries
29 ===================
30
31 Countries currently supported by ``localflavor`` are:
32
33     * Argentina_
34     * Australia_
35     * Brazil_
36     * Canada_
37     * Chile_
38     * Finland_
39     * France_
40     * Germany_
41     * Holland_
42     * Iceland_
43     * India_
44     * Italy_
45     * Japan_
46     * Mexico_
47     * Norway_
48     * Peru_
49     * Poland_
50     * Slovakia_
51     * `South Africa`_
52     * Spain_
53     * Switzerland_
54     * `United Kingdom`_
55     * `United States of America`_
56
57 The ``localflavor`` package also includes a ``generic`` subpackage, containing
58 useful code that is not specific to one particular country or culture.
59 Currently, it defines date and datetime input fields based on those from
60 newforms_, but with non-US default formats. Here's an example of how to use
61 them::
62
63     from django import newforms as forms
64     from django.contrib.localflavor import generic
65
66     class MyForm(forms.Form):
67         my_date_field = generic.forms.DateField()
68
69 .. _ISO 3166 country codes: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
70 .. _Argentina: `Argentina (django.contrib.localflavor.ar)`_
71 .. _Australia: `Australia (django.contrib.localflavor.au)`_
72 .. _Brazil: `Brazil (django.contrib.localflavor.br)`_
73 .. _Canada: `Canada (django.contrib.localflavor.ca)`_
74 .. _Chile: `Chile (django.contrib.localflavor.cl)`_
75 .. _Finland: `Finland (django.contrib.localflavor.fi)`_
76 .. _France: `France (django.contrib.localflavor.fr)`_
77 .. _Germany: `Germany (django.contrib.localflavor.de)`_
78 .. _Holland: `Holland (django.contrib.localflavor.nl)`_
79 .. _Iceland: `Iceland (django.contrib.localflavor.is\_)`_
80 .. _India: `India (django.contrib.localflavor.in\_)`_
81 .. _Italy: `Italy (django.contrib.localflavor.it)`_
82 .. _Japan: `Japan (django.contrib.localflavor.jp)`_
83 .. _Mexico: `Mexico (django.contrib.localflavor.mx)`_
84 .. _Norway: `Norway (django.contrib.localflavor.no)`_
85 .. _Peru: `Peru (django.contrib.localflavor.pe)`_
86 .. _Poland: `Poland (django.contrib.localflavor.pl)`_
87 .. _Slovakia: `Slovakia (django.contrib.localflavor.sk)`_
88 .. _South Africa: `South Africa (django.contrib.localflavor.za)`_
89 .. _Spain: `Spain (django.contrib.localflavor.es)`_
90 .. _Switzerland: `Switzerland (django.contrib.localflavor.ch)`_
91 .. _United Kingdom: `United Kingdom (django.contrib.localflavor.uk)`_
92 .. _United States of America: `United States of America (django.contrib.localflavor.us)`_
93 .. _newforms: ../newforms/
94
95 Adding flavors
96 ==============
97
98 We'd love to add more of these to Django, so please `create a ticket`_ with
99 any code you'd like to contribute. One thing we ask is that you please use
100 Unicode objects (``u'mystring'``) for strings, rather than setting the encoding
101 in the file. See any of the existing flavors for examples.
102
103 .. _create a ticket: http://code.djangoproject.com/simpleticket
104
105 Argentina (``django.contrib.localflavor.ar``)
106 =============================================
107
108 ARPostalCodeField
109 -----------------
110
111 A form field that validates input as either a classic four-digit Argentinian
112 postal code or a CPA_.
113
114 .. _CPA: http://www.correoargentino.com.ar/consulta_cpa/home.php
115
116 ARDNIField
117 ----------
118
119 A form field that validates input as a Documento Nacional de Identidad (DNI)
120 number.
121
122 ARCUITField
123 -----------
124
125 A form field that validates input as a Código Único de Identificación
126 Tributaria (CUIT) number.
127
128 ARProvinceSelect
129 ----------------
130
131 A ``Select`` widget that uses a list of Argentina's provinces and autonomous
132 cities as its choices.
133
134 Australia (``django.contrib.localflavor.au``)
135 =============================================
136
137 AUPostCodeField
138 ---------------
139
140 A form field that validates input as an Australian postcode.
141
142 AUPhoneNumberField
143 ------------------
144
145 A form field that validates input as an Australian phone number. Valid numbers
146 have ten digits.
147
148 AUStateSelect
149 -------------
150
151 A ``Select`` widget that uses a list of Australian states/territories as its
152 choices.
153
154 Brazil (``django.contrib.localflavor.br``)
155 ==========================================
156
157 BRPhoneNumberField
158 ------------------
159
160 A form field that validates input as a Brazilian phone number, with the format
161 XX-XXXX-XXXX.
162
163 BRZipCodeField
164 --------------
165
166 A form field that validates input as a Brazilian zip code, with the format
167 XXXXX-XXX.
168
169 BRStateSelect
170 -------------
171
172 A ``Select`` widget that uses a list of Brazilian states/territories as its
173 choices.
174
175 Canada (``django.contrib.localflavor.ca``)
176 ==========================================
177
178 CAPhoneNumberField
179 ------------------
180
181 A form field that validates input as a Canadian phone number, with the format
182 XXX-XXX-XXXX.
183
184 CAPostalCodeField
185 -----------------
186
187 A form field that validates input as a Canadian postal code, with the format
188 XXX XXX.
189
190 CAProvinceField
191 ---------------
192
193 A form field that validates input as a Canadian province name or abbreviation.
194
195 CASocialInsuranceNumberField
196 ----------------------------
197
198 A form field that validates input as a Canadian Social Insurance Number (SIN).
199 A valid number must have the format XXX-XXX-XXX and pass a `Luhn mod-10
200 checksum`_.
201
202 .. _Luhn mod-10 checksum: http://en.wikipedia.org/wiki/Luhn_algorithm
203
204 CAProvinceSelect
205 ----------------
206
207 A ``Select`` widget that uses a list of Canadian provinces and territories as
208 its choices.
209
210 Chile (``django.contrib.localflavor.cl``)
211 =========================================
212
213 CLRutField
214 ----------
215
216 A form field that validates input as a Chilean national identification number
217 ('Rol Unico Tributario' or RUT). The valid format is XX.XXX.XXX-X.
218
219 CLRegionSelect
220 --------------
221
222 A ``Select`` widget that uses a list of Chilean regions (Regiones) as its
223 choices.
224
225 Finland (``django.contrib.localflavor.fi``)
226 ===========================================
227
228 FISocialSecurityNumber
229 ----------------------
230
231 A form field that validates input as a Finnish social security number.
232
233 FIZipCodeField
234 --------------
235
236 A form field that validates input as a Finnish zip code. Valid codes
237 consist of five digits.
238
239 FIMunicipalitySelect
240 --------------------
241
242 A ``Select`` widget that uses a list of Finnish municipalities as its
243 choices.
244
245 France (``django.contrib.localflavor.fr``)
246 ==========================================
247
248 FRPhoneNumberField
249 ------------------
250
251 A form field that validates input as a French local phone number. The
252 correct format is 0X XX XX XX XX. 0X.XX.XX.XX.XX and 0XXXXXXXXX validate
253 but are corrected to 0X XX XX XX XX.
254
255 FRZipCodeField
256 --------------
257
258 A form field that validates input as a French zip code. Valid codes
259 consist of five digits.
260
261 FRDepartmentSelect
262 ------------------
263
264 A ``Select`` widget that uses a list of French departments as its choices.
265
266 Germany (``django.contrib.localflavor.de``)
267 ===========================================
268
269 DEIdentityCardNumberField
270 -------------------------
271
272 A form field that validates input as a German identity card number
273 (Personalausweis_). Valid numbers have the format
274 XXXXXXXXXXX-XXXXXXX-XXXXXXX-X, with no group consisting entirely of zeroes.
275
276 .. _Personalausweis: http://de.wikipedia.org/wiki/Personalausweis
277
278 DEZipCodeField
279 --------------
280
281 A form field that validates input as a German zip code. Valid codes
282 consist of five digits.
283
284 DEStateSelect
285 -------------
286
287 A ``Select`` widget that uses a list of German states as its choices.
288
289 Holland (``django.contrib.localflavor.nl``)
290 ===========================================
291
292 NLPhoneNumberField
293 ------------------
294
295 A form field that validates input as a Dutch telephone number.
296
297 NLSofiNumberField
298 -----------------
299
300 A form field that validates input as a Dutch social security number
301 (SoFI/BSN).
302
303 NLZipCodeField
304 --------------
305
306 A form field that validates input as a Dutch zip code.
307
308 NLProvinceSelect
309 ----------------
310
311 A ``Select`` widget that uses a list of Dutch provinces as its list of
312 choices.
313
314 Iceland (``django.contrib.localflavor.is_``)
315 ============================================
316
317 ISIdNumberField
318 ---------------
319
320 A form field that validates input as an Icelandic identification number
321 (kennitala). The format is XXXXXX-XXXX.
322
323 ISPhoneNumberField
324 ------------------
325
326 A form field that validates input as an Icelandtic phone number (seven
327 digits with an optional hyphen or space after the first three digits).
328
329 ISPostalCodeSelect
330 ------------------
331
332 A ``Select`` widget that uses a list of Icelandic postal codes as its
333 choices.
334
335 India (``django.contrib.localflavor.in_``)
336 ==========================================
337
338 INStateField
339 ------------
340
341 A form field that validates input as an Indian state/territory name or
342 abbreviation. Input is normalized to the standard two-letter vehicle
343 registration abbreviation for the given state or territory.
344
345 INZipCodeField
346 --------------
347
348 A form field that validates input as an Indian zip code, with the
349 format XXXXXXX.
350
351 INStateSelect
352 -------------
353
354 A ``Select`` widget that uses a list of Indian states/territories as its
355 choices.
356
357 Italy (``django.contrib.localflavor.it``)
358 =========================================
359
360 ITSocialSecurityNumberField
361 ---------------------------
362
363 A form field that validates input as an Italian social security number
364 (`codice fiscale`_).
365
366 .. _codice fiscale: http://www.agenziaentrate.it/ilwwcm/connect/Nsi/Servizi/Codice+fiscale+-+tessera+sanitaria/Codice+fiscale/NSI+Informazioni+sulla+codificazione+delle+persone+fisiche
367
368 ITVatNumberField
369 ----------------
370
371 A form field that validates Italian VAT numbers (partita IVA).
372
373 ITZipCodeField
374 --------------
375
376 A form field that validates input as an Italian zip code. Valid codes
377 must have five digits.
378
379 ITProvinceSelect
380 ----------------
381
382 A ``Select`` widget that uses a list of Italian provinces as its choices.
383
384 ITRegionSelect
385 --------------
386
387 A ``Select`` widget that uses a list of Italian regions as its choices.
388
389 Japan (``django.contrib.localflavor.jp``)
390 =========================================
391
392 JPPostalCodeField
393 -----------------
394
395 A form field that validates input as a Japanese postcode. It accepts seven
396 digits, with or without a hyphen.
397
398 JPPrefectureSelect
399 ------------------
400
401 A ``Select`` widget that uses a list of Japanese prefectures as its choices.
402
403 Mexico (``django.contrib.localflavor.mx``)
404 ==========================================
405
406 MXStateSelect
407 -------------
408
409 A ``Select`` widget that uses a list of Mexican states as its choices.
410
411 Norway (``django.contrib.localflavor.no``)
412 ==========================================
413
414 NOSocialSecurityNumber
415 ----------------------
416
417 A form field that validates input as a Norwegian social security number
418 (personnummer_).
419
420 .. _personnummer: http://no.wikipedia.org/wiki/Personnummer
421
422 NOZipCodeField
423 --------------
424
425 A form field that validates input as a Norwegian zip code. Valid codes
426 have four digits.
427
428 NOMunicipalitySelect
429 --------------------
430
431 A ``Select`` widget that uses a list of Norwegian municipalities (fylker) as
432 its choices.
433
434 Peru (``django.contrib.localflavor.pe``)
435 ========================================
436
437 PEDNIField
438 ----------
439
440 A form field that validates input as a DNI (Peruvian national identity)
441 number.
442
443 PERUCField
444 ----------
445
446 A form field that validates input as an RUC (Registro Unico de
447 Contribuyentes) number. Valid RUC numbers have 11 digits.
448
449 PEDepartmentSelect
450 ------------------
451
452 A ``Select`` widget that uses a list of Peruvian Departments as its choices.
453
454 Poland (``django.contrib.localflavor.pl``)
455 ==========================================
456
457 PLNationalIdentificationNumberField
458 -----------------------------------
459
460 A form field that validates input as a Polish national identification number
461 (PESEL_).
462
463 .. _PESEL: http://en.wikipedia.org/wiki/PESEL
464
465 PLNationalBusinessRegisterField
466 -------------------------------
467
468 A form field that validates input as a Polish National Official Business
469 Register Number (REGON_), having either seven or nine digits. The checksum
470 algorithm used for REGONs is documented at
471 http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.
472
473 .. _REGON: http://www.stat.gov.pl/bip/regon_ENG_HTML.htm
474
475 PLPostalCodeField
476 -----------------
477
478 A form field that validates input as a Polish postal code. The valid format
479 is XX-XXX, where X is a digit.
480
481 PLTaxNumberField
482 ----------------
483
484 A form field that validates input as a Polish Tax Number (NIP). Valid
485 formats are XXX-XXX-XX-XX or XX-XX-XXX-XXX. The checksum algorithm used
486 for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.
487
488 PLAdministrativeUnitSelect
489 --------------------------
490
491 A ``Select`` widget that uses a list of Polish administrative units as its
492 choices.
493
494 PLVoivodeshipSelect
495 -------------------
496
497 A ``Select`` widget that uses a list of Polish voivodeships (administrative
498 provinces) as its choices.
499
500 Slovakia (``django.contrib.localflavor.sk``)
501 ============================================
502
503 SKPostalCodeField
504 -----------------
505
506 A form field that validates input as a Slovak postal code. Valid formats
507 are XXXXX or XXX XX, where X is a digit.
508
509 SKDistrictSelect
510 ----------------
511
512 A ``Select`` widget that uses a list of Slovak districts as its choices.
513
514 SKRegionSelect
515 --------------
516
517 A ``Select`` widget that uses a list of Slovak regions as its choices.
518
519 South Africa (``django.contrib.localflavor.za``)
520 ================================================
521
522 ZAIDField
523 ---------
524
525 A form field that validates input as a South African ID number. Validation
526 uses the Luhn checksum and a simplistic (i.e., not entirely accurate) check
527 for birth date.
528
529 ZAPostCodeField
530 ---------------
531
532 A form field that validates input as a South African postcode. Valid
533 postcodes must have four digits.
534
535 Spain (``django.contrib.localflavor.es``)
536 =========================================
537
538 ESIdentityCardNumberField
539 -------------------------
540
541 A form field that validates input as a Spanish NIF/NIE/CIF (Fiscal
542 Identification Number) code.
543
544 ESCCCField
545 ----------
546
547 A form field that validates input as a Spanish bank account number (Codigo
548 Cuenta Cliente or CCC). A valid CCC number has the format
549 EEEE-OOOO-CC-AAAAAAAAAA, where the E, O, C and A digits denote the entity,
550 office, checksum and account, respectively. The first checksum digit
551 validates the entity and office. The second checksum digit validates the
552 account. It is also valid to use a space as a delimiter, or to use no
553 delimiter.
554
555 ESPhoneNumberField
556 ------------------
557
558 A form field that validates input as a Spanish phone number. Valid numbers
559 have nine digits, the first of which is 6, 8 or 9.
560
561 ESPostalCodeField
562 -----------------
563
564 A form field that validates input as a Spanish postal code. Valid codes
565 have five digits, the first two being in the range 01 to 52, representing
566 the province.
567
568 ESProvinceSelect
569 ----------------
570
571 A ``Select`` widget that uses a list of Spanish provinces as its choices.
572
573 ESRegionSelect
574 --------------
575
576 A ``Select`` widget that uses a list of Spanish regions as its choices.
577
578 Switzerland (``django.contrib.localflavor.ch``)
579 ===============================================
580
581 CHIdentityCardNumberField
582 -------------------------
583
584 A form field that validates input as a Swiss identity card number.
585 A valid number must confirm to the X1234567<0 or 1234567890 format and
586 have the correct checksums -- see http://adi.kousz.ch/artikel/IDCHE.htm.
587
588 CHPhoneNumberField
589 ------------------
590
591 A form field that validates input as a Swiss phone number. The correct
592 format is 0XX XXX XX XX. 0XX.XXX.XX.XX and 0XXXXXXXXX validate but are
593 corrected to 0XX XXX XX XX.
594
595 CHZipCodeField
596 --------------
597
598 A form field that validates input as a Swiss zip code. Valid codes
599 consist of four digits.
600
601 CHStateSelect
602 -------------
603
604 A ``Select`` widget that uses a list of Swiss states as its choices.
605
606 United Kingdom (``django.contrib.localflavor.uk``)
607 ==================================================
608
609 UKPostcodeField
610 ---------------
611
612 A form field that validates input as a UK postcode. The regular
613 expression used is sourced from the schema for British Standard BS7666
614 address types at http://www.govtalk.gov.uk/gdsc/schemas/bs7666-v2-0.xsd.
615
616 UKCountySelect
617 --------------
618
619 A ``Select`` widget that uses a list of UK counties/regions as its choices.
620
621 UKNationSelect
622 --------------
623
624 A ``Select`` widget that uses a list of UK nations as its choices.
625
626 United States of America (``django.contrib.localflavor.us``)
627 ============================================================
628
629 USPhoneNumberField
630 ------------------
631
632 A form field that validates input as a U.S. phone number.
633
634 USSocialSecurityNumberField
635 ---------------------------
636
637 A form field that validates input as a U.S. Social Security Number (SSN).
638 A valid SSN must obey the following rules:
639
640     * Format of XXX-XX-XXXX
641     * No group of digits consisting entirely of zeroes
642     * Leading group of digits cannot be 666
643     * Number not in promotional block 987-65-4320 through 987-65-4329
644     * Number not one known to be invalid due to widespread promotional
645       use or distribution (e.g., the Woolworth's number or the 1962
646       promotional number)
647
648 USStateField
649 ------------
650
651 A form field that validates input as a U.S. state name or abbreviation. It
652 normalizes the input to the standard two-letter postal service abbreviation
653 for the given state.
654
655 USZipCodeField
656 --------------
657
658 A form field that validates input as a U.S. ZIP code. Valid formats are
659 XXXXX or XXXXX-XXXX.
660
661 USStateSelect
662 -------------
663
664 A form ``Select`` widget that uses a list of U.S. states/territories as its
665 choices.
Note: See TracBrowser for help on using the browser.