Django

Code

Changeset 6946

Show
Ignore:
Timestamp:
12/18/07 21:52:13 (9 months ago)
Author:
adrian
Message:

Edited docs/localflavor.txt changes from [6849]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/localflavor.txt

    r6931 r6946  
    33========================== 
    44 
    5 Django comes with assorted pieces of code that are useful only for a particular 
    6 country or culture.  These pieces of code are organized as a set of 
     5Following its "batteries included" philosophy, Django comes with assorted 
     6pieces of code that are useful for particular countries or cultures. These are 
     7called the "local flavor" add-ons and live in the ``django.contrib.localflavor`` 
     8package. 
     9 
     10Inside that package, country- or culture-specific code is organized into 
    711subpackages, named using `ISO 3166 country codes`_. 
    812 
    9 .. _ISO 3166 country codes: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm 
    10  
    1113Most of the ``localflavor`` add-ons are localized form components deriving from 
    12 the newforms_ framework.  To use one of these localized components, just import 
    13 the relevant subpackage.  For example, a form with a field for French telephone 
    14 numbers is created like so:: 
     14the newforms_ framework -- for example, a ``USStateField`` that knows how to 
     15validate U.S. state abbreviations, and a ``FISocialSecurityNumber`` that knows 
     16how to validate Finnish social security numbers. 
     17 
     18To use one of these localized components, just import the relevant subpackage. 
     19For example, here's how you can create a form with a field representing a 
     20French telephone number:: 
    1521 
    1622    from django import newforms as forms 
     
    2026        my_french_phone_no = fr.forms.FRPhoneNumberField() 
    2127 
     28Supported countries 
     29=================== 
     30 
    2231Countries currently supported by ``localflavor`` are: 
    2332 
    24 * Argentina_ 
    25 * Australia_ 
    26 * Brazil_ 
    27 * Canada_ 
    28 * Chile_ 
    29 * Finland_ 
    30 * France_ 
    31 * Germany_ 
    32 * Holland_ 
    33 * Iceland_ 
    34 * India_ 
    35 * Italy_ 
    36 * Japan_ 
    37 * Mexico_ 
    38 * Norway_ 
    39 * Peru_ 
    40 * Poland_ 
    41 * Slovakia_ 
    42 * `South Africa`_ 
    43 * Spain_ 
    44 * Switzerland_ 
    45 * `United Kingdom`_ 
    46 * `United States of America`_ 
    47  
     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 
     57The ``localflavor`` package also includes a ``generic`` subpackage, containing 
     58useful code that is not specific to one particular country or culture. 
     59Currently, it defines date and datetime input fields based on those from 
     60newforms_, but with non-US default formats. Here's an example of how to use 
     61them:: 
     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 
    4870.. _Argentina: `Argentina (django.contrib.localflavor.ar)`_ 
    4971.. _Australia: `Australia (django.contrib.localflavor.au)`_ 
     
    6991.. _United Kingdom: `United Kingdom (django.contrib.localflavor.uk)`_ 
    7092.. _United States of America: `United States of America (django.contrib.localflavor.us)`_ 
    71  
    72 The ``localflavor`` add-on also includes the ``generic`` subpackage, containing 
    73 useful code that is not specific to one particular country or culture. 
    74 Currently, it defines date and date & time input fields based on those from 
    75 newforms_, but with non-US default formats.  Here's an example of how to use 
    76 them:: 
    77  
    78     from django import newforms as forms 
    79     from django.contrib.localflavor import generic 
    80  
    81     class MyForm(forms.Form): 
    82         my_date_field = generic.forms.DateField() 
    83  
    8493.. _newforms: ../newforms/ 
    8594 
    86  
    87 .. admonition:: Adding a Flavor 
    88  
    89    We'd love to add more of these to Django, so please create a ticket for 
    90    anything that you've found useful. Please use unicode objects 
    91    (``u'mystring'``) for strings, rather than setting the encoding in the file 
    92    (see any of the existing flavors for examples). 
    93  
     95Adding flavors 
     96============== 
     97 
     98We'd love to add more of these to Django, so please `create a ticket`_ with 
     99any code you'd like to contribute. One thing we ask is that you please use 
     100Unicode objects (``u'mystring'``) for strings, rather than setting the encoding 
     101in the file. See any of the existing flavors for examples. 
    94102 
    95103Argentina (``django.contrib.localflavor.ar``) 
     
    109117A ``Select`` widget that uses a list of Argentina's provinces as its choices. 
    110118 
    111  
    112119Australia (``django.contrib.localflavor.au``) 
    113120============================================= 
     
    130137choices. 
    131138 
    132  
    133139Brazil (``django.contrib.localflavor.br``) 
    134140========================================== 
     
    151157A ``Select`` widget that uses a list of Brazilian states/territories as its 
    152158choices. 
    153  
    154159 
    155160Canada (``django.contrib.localflavor.ca``) 
     
    188193its choices. 
    189194 
    190  
    191195Chile (``django.contrib.localflavor.cl``) 
    192196========================================= 
     
    204208choices. 
    205209 
    206  
    207210Finland (``django.contrib.localflavor.fi``) 
    208211=========================================== 
     
    216219-------------- 
    217220 
    218 A form field that validates input as a Finnish zip code. Valid codes 
     221A form field that validates input as a Finnish zip code. Valid codes 
    219222consist of five digits. 
    220223 
     
    225228choices. 
    226229 
    227  
    228230France (``django.contrib.localflavor.fr``) 
    229231========================================== 
     
    233235 
    234236A form field that validates input as a French local phone number. The 
    235 correct format is 0X XX XX XX XX. 0X.XX.XX.XX.XX and 0XXXXXXXXX validate 
     237correct format is 0X XX XX XX XX. 0X.XX.XX.XX.XX and 0XXXXXXXXX validate 
    236238but are corrected to 0X XX XX XX XX. 
    237239 
     
    239241-------------- 
    240242 
    241 A form field that validates input as a French zip code. Valid codes 
     243A form field that validates input as a French zip code. Valid codes 
    242244consist of five digits. 
    243245 
     
    246248 
    247249A ``Select`` widget that uses a list of French departments as its choices. 
    248  
    249250 
    250251Germany (``django.contrib.localflavor.de``) 
     
    255256 
    256257A form field that validates input as a German identity card number 
    257 (Personalausweis_). Valid numbers have the format 
     258(Personalausweis_). Valid numbers have the format 
    258259XXXXXXXXXXX-XXXXXXX-XXXXXXX-X, with no group consisting entirely of zeroes. 
    259260 
     
    263264-------------- 
    264265 
    265 A form field that validates input as a German zip code. Valid codes 
     266A form field that validates input as a German zip code. Valid codes 
    266267consist of five digits. 
    267268 
     
    271272A ``Select`` widget that uses a list of German states as its choices. 
    272273 
    273  
    274274Holland (``django.contrib.localflavor.nl``) 
    275275=========================================== 
     
    297297choices. 
    298298 
    299  
    300299Iceland (``django.contrib.localflavor.is_``) 
    301300============================================ 
     
    305304 
    306305A form field that validates input as an Icelandic identification number 
    307 (kennitala). The format is XXXXXX-XXXX. 
     306(kennitala). The format is XXXXXX-XXXX. 
    308307 
    309308ISPhoneNumberField 
     
    319318choices. 
    320319 
    321  
    322320India (``django.contrib.localflavor.in_``) 
    323321========================================== 
     
    327325 
    328326A form field that validates input as an Indian state/territory name or 
    329 abbreviation. Input is normalized to the standard two-letter vehicle 
     327abbreviation. Input is normalized to the standard two-letter vehicle 
    330328registration abbreviation for the given state or territory. 
    331329 
     
    342340choices. 
    343341 
    344  
    345342Italy (``django.contrib.localflavor.it``) 
    346343========================================= 
     
    362359-------------- 
    363360 
    364 A form field that validates input as an Italian zip code. Valid codes 
     361A form field that validates input as an Italian zip code. Valid codes 
    365362must have five digits. 
    366363 
     
    374371 
    375372A ``Select`` widget that uses a list of Italian regions as its choices. 
    376  
    377373 
    378374Japan (``django.contrib.localflavor.jp``) 
     
    382378----------------- 
    383379 
    384 A form field that validates input as a Japanese postcode. 
    385 It accepts seven digits, with or without a hyphen. 
     380A form field that validates input as a Japanese postcode. It accepts seven 
     381digits, with or without a hyphen. 
    386382 
    387383JPPrefectureSelect 
     
    389385 
    390386A ``Select`` widget that uses a list of Japanese prefectures as its choices. 
    391  
    392387 
    393388Mexico (``django.contrib.localflavor.mx``) 
     
    399394A ``Select`` widget that uses a list of Mexican states as its choices. 
    400395 
    401  
    402396Norway (``django.contrib.localflavor.no``) 
    403397========================================== 
     
    414408-------------- 
    415409 
    416 A form field that validates input as a Norwegian zip code. Valid codes 
     410A form field that validates input as a Norwegian zip code. Valid codes 
    417411have four digits. 
    418412 
     
    423417its choices. 
    424418 
    425  
    426419Peru (``django.contrib.localflavor.pe``) 
    427420======================================== 
     
    437430 
    438431A form field that validates input as an RUC (Registro Unico de 
    439 Contribuyentes) number. Valid RUC numbers have eleven digits. 
     432Contribuyentes) number. Valid RUC numbers have 11 digits. 
    440433 
    441434PEDepartmentSelect 
     
    443436 
    444437A ``Select`` widget that uses a list of Peruvian Departments as its choices. 
    445  
    446438 
    447439Poland (``django.contrib.localflavor.pl``) 
     
    460452 
    461453A form field that validates input as a Polish National Official Business 
    462 Register Number (REGON_), having either seven or nine digits. The checksum 
     454Register Number (REGON_), having either seven or nine digits. The checksum 
    463455algorithm used for REGONs is documented at 
    464456http://wipos.p.lodz.pl/zylla/ut/nip-rego.html. 
     
    469461----------------- 
    470462 
    471 A form field that validates input as a Polish postal code. The valid format 
     463A form field that validates input as a Polish postal code. The valid format 
    472464is XX-XXX, where X is a digit. 
    473465 
     
    475467---------------- 
    476468 
    477 A form field that validates input as a Polish Tax Number (NIP). Valid 
    478 formats are XXX-XXX-XX-XX or XX-XX-XXX-XXX. The checksum algorithm used 
     469A form field that validates input as a Polish Tax Number (NIP). Valid 
     470formats are XXX-XXX-XX-XX or XX-XX-XXX-XXX. The checksum algorithm used 
    479471for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html. 
    480472 
     
    491483provinces) as its choices. 
    492484 
    493  
    494485Slovakia (``django.contrib.localflavor.sk``) 
    495486============================================ 
     
    498489----------------- 
    499490 
    500 A form field that validates input as a Slovak postal code. Valid formats 
     491A form field that validates input as a Slovak postal code. Valid formats 
    501492are XXXXX or XXX XX, where X is a digit. 
    502493 
     
    510501 
    511502A ``Select`` widget that uses a list of Slovak regions as its choices. 
    512  
    513503 
    514504South Africa (``django.contrib.localflavor.za``) 
     
    518508--------- 
    519509 
    520 A form field that validates input as a South African ID number. Validation 
     510A form field that validates input as a South African ID number. Validation 
    521511uses the Luhn checksum and a simplistic (i.e., not entirely accurate) check 
    522512for birth date. 
     
    525515--------------- 
    526516 
    527 A form field that validates input as a South African postcode. Valid 
     517A form field that validates input as a South African postcode. Valid 
    528518postcodes must have four digits. 
    529  
    530519 
    531520Spain (``django.contrib.localflavor.es``) 
     
    542531 
    543532A form field that validates input as a Spanish bank account number (Codigo 
    544 Cuenta Cliente or CCC). A valid CCC number has the format 
     533Cuenta Cliente or CCC). A valid CCC number has the format 
    545534EEEE-OOOO-CC-AAAAAAAAAA, where the E, O, C and A digits denote the entity, 
    546 office, checksum and account, respectively. The first checksum digit 
    547 validates the entity and office. The second checksum digit validates the 
    548 account. It is also valid to use a space as a delimiter, or to use no 
     535office, checksum and account, respectively. The first checksum digit 
     536validates the entity and office. The second checksum digit validates the 
     537account. It is also valid to use a space as a delimiter, or to use no 
    549538delimiter. 
    550539 
     
    552541------------------ 
    553542 
    554 A form field that validates input as a Spanish phone number. Valid numbers 
     543A form field that validates input as a Spanish phone number. Valid numbers 
    555544have nine digits, the first of which is 6, 8 or 9. 
    556545 
     
    558547----------------- 
    559548 
    560 A form field that validates input as a Spanish postal code. Valid codes 
     549A form field that validates input as a Spanish postal code. Valid codes 
    561550have five digits, the first two being in the range 01 to 52, representing 
    562551the province. 
     
    571560 
    572561A ``Select`` widget that uses a list of Spanish regions as its choices. 
    573  
    574562 
    575563Switzerland (``django.contrib.localflavor.ch``) 
     
    586574------------------ 
    587575 
    588 A form field that validates input as a Swiss phone number. The correct 
    589 format is 0XX XXX XX XX. 0XX.XXX.XX.XX and 0XXXXXXXXX validate but are 
     576A form field that validates input as a Swiss phone number. The correct 
     577format is 0XX XXX XX XX. 0XX.XXX.XX.XX and 0XXXXXXXXX validate but are 
    590578corrected to 0XX XXX XX XX. 
    591579 
     
    593581-------------- 
    594582 
    595 A form field that validates input as a Swiss zip code. Valid codes 
     583A form field that validates input as a Swiss zip code. Valid codes 
    596584consist of four digits. 
    597585 
     
    600588 
    601589A ``Select`` widget that uses a list of Swiss states as its choices. 
    602  
    603590 
    604591United Kingdom (``django.contrib.localflavor.uk``) 
     
    622609A ``Select`` widget that uses a list of UK nations as its choices. 
    623610 
    624  
    625611United States of America (``django.contrib.localflavor.us``)  
    626612============================================================ 
     
    637623A valid SSN must obey the following rules: 
    638624 
    639 * Format of XXX-XX-XXXX 
    640 * No group of digits consisting entirely of zeroes 
    641 * Leading group of digits cannot be 666 
    642 * Number not in promotional block 987-65-4320 through 987-65-4329 
    643 * Number not one known to be invalid due to widespread promotional 
    644   use or distribution (e.g., the Woolworth's number or the 1962 
    645   promotional number) 
     625    * Format of XXX-XX-XXXX 
     626    * No group of digits consisting entirely of zeroes 
     627    * Leading group of digits cannot be 666 
     628    * Number not in promotional block 987-65-4320 through 987-65-4329 
     629    * Number not one known to be invalid due to widespread promotional 
     630      use or distribution (e.g., the Woolworth's number or the 1962 
     631      promotional number) 
    646632 
    647633USStateField 
     
    655641-------------- 
    656642 
    657 A form field that validates input as a U.S. zip code. Valid formats are 
     643A form field that validates input as a U.S. ZIP code. Valid formats are 
    658644XXXXX or XXXXX-XXXX. 
    659645 
     
    661647------------- 
    662648 
    663 A form Select widget that uses a list of U.S. states/territories as its 
    664 choices. 
     649A form ``Select`` widget that uses a list of U.S. states/territories as its 
     650choices.