United States of America (us
)¶
Forms¶
USA-specific Form helpers.
-
class
localflavor.us.forms.
USPSSelect
(attrs=None)[source]¶ A Select widget that uses a list of US Postal Service codes as its choices.
Note
If you are looking for a form field that validates U.S. ZIP codes please use
USZipCodeField
.
-
class
localflavor.us.forms.
USPhoneNumberField
(max_length=None, min_length=None, strip=True, *args, **kwargs)[source]¶ A form field that validates input as a U.S. phone number.
-
class
localflavor.us.forms.
USSocialSecurityNumberField
(max_length=None, min_length=None, strip=True, *args, **kwargs)[source]¶ A United States Social Security number.
Checks the following rules to determine whether the number is valid:
- Conforms to the XXX-XX-XXXX format.
- No group consists entirely of zeroes.
- The leading group is not “666” (block “666” will never be allocated).
- The number is not in the promotional block 987-65-4320 through 987-65-4329, which are permanently invalid.
- The number is not one known to be invalid due to otherwise widespread promotional use or distribution (e.g., the Woolworth’s number or the 1962 promotional number).
New in version 1.1.
-
class
localflavor.us.forms.
USStateField
(required=True, widget=None, label=None, initial=None, help_text='', error_messages=None, show_hidden_initial=False, validators=[], localize=False, disabled=False, label_suffix=None)[source]¶ A form field that validates its input is a U.S. state name or abbreviation.
It normalizes the input to the standard two-leter postal service abbreviation for the given state.
-
class
localflavor.us.forms.
USStateSelect
(attrs=None)[source]¶ A Select widget that uses a list of U.S. states/territories as its choices.
-
class
localflavor.us.forms.
USZipCodeField
(max_length=None, min_length=None, *args, **kwargs)[source]¶ A form field that validates input as a U.S. ZIP code.
Valid formats are XXXXX or XXXXX-XXXX.
Note
If you are looking for a form field with a list of U.S. Postal Service locations please use
USPSSelect
.New in version 1.1.
Whitespace around the ZIP code is accepted and automatically trimmed.
Models¶
-
class
localflavor.us.models.
PhoneNumberField
(*args, **kwargs)[source]¶ A
CharField
that checks that the value is a valid U.S.A.-style phone number.(in the format
XXX-XXX-XXXX
).
-
class
localflavor.us.models.
USPostalCodeField
(*args, **kwargs)[source]¶ A model field that stores the two-letter U.S. Postal Service abbreviation in the database.
Forms represent it as a
USPSSelect`
field.Note
If you are looking for a model field that validates U.S. ZIP codes please use
USZipCodeField
.
-
class
localflavor.us.models.
USSocialSecurityNumberField
(*args, **kwargs)[source]¶ A model field that stores the security number in the format
XXX-XX-XXXX
.Forms represent it as
forms.USSocialSecurityNumberField
field.New in version 1.1.
-
class
localflavor.us.models.
USStateField
(*args, **kwargs)[source]¶ A model field that stores the two-letter U.S. state abbreviation in the database.
Forms represent it as a
forms.USStateField
field.
-
class
localflavor.us.models.
USZipCodeField
(*args, **kwargs)[source]¶ A model field that stores the U.S. ZIP code in the database.
Forms represent it as a
USZipCodeField
field.Note
If you are looking for a model field with a list of U.S. Postal Service locations please use
USPostalCodeField
.New in version 1.1.
Data¶
-
localflavor.us.us_states.
CONTIGUOUS_STATES
= (('AL', 'Alabama'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MD', 'Maryland'), ('MA', 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS', 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'), ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM', 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North Dakota'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA', 'Pennsylvania'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))¶ The 48 contiguous states, plus the District of Columbia.
-
localflavor.us.us_states.
NON_CONTIGUOUS_STATES
= (('AK', 'Alaska'), ('HI', 'Hawaii'))¶ Non contiguous states (Not connected to mainland USA)
-
localflavor.us.us_states.
US_TERRITORIES
= (('AS', 'American Samoa'), ('GU', 'Guam'), ('MP', 'Northern Mariana Islands'), ('PR', 'Puerto Rico'), ('VI', 'Virgin Islands'))¶ Non-state territories.
-
localflavor.us.us_states.
ARMED_FORCES_STATES
= (('AA', 'Armed Forces Americas'), ('AE', 'Armed Forces Europe'), ('AP', 'Armed Forces Pacific'))¶ Military postal “states”. Note that ‘AE’ actually encompasses Europe, Canada, Africa and the Middle East.
-
localflavor.us.us_states.
COFA_STATES
= (('FM', 'Federated States of Micronesia'), ('MH', 'Marshall Islands'), ('PW', 'Palau'))¶ Non-US locations serviced by USPS (under Compact of Free Association).
-
localflavor.us.us_states.
OBSOLETE_STATES
= (('CM', 'Commonwealth of the Northern Mariana Islands'), ('CZ', 'Panama Canal Zone'), ('PI', 'Philippine Islands'), ('TT', 'Trust Territory of the Pacific Islands'))¶ Obsolete abbreviations (no longer US territories/USPS service, or code changed).
-
localflavor.us.us_states.
US_STATES
= CONTIGUOUS_STATES + NON_CONTIGUOUS_STATES¶ All US states.
This tuple is lazily generated and may not work as expected in all cases due to tuple optimizations in the Python interpreter which do not account for lazily generated tuples. For example:
US_STATES + ('XX', _('Select a State'))
should work as expected, but:
('XX', _('Select a State')) + US_STATES
may throw:
TypeError: can only concatenate tuple (not "proxy") to tuple
due to a Python optimization that causes the concatenation to occur before US_STATES has been lazily generated. To work around these issues, you can use a slice index (
[:]
) to force the generation of US_STATES before any other operations are processed by the Python interpreter:('XX', _('Select a State')) + US_STATES[:]
-
localflavor.us.us_states.
STATE_CHOICES
= CONTIGUOUS_STATES + NON_CONTIGUOUS_STATES + US_TERRITORIES + ARMED_FORCES_STATES¶ All US states and territories plus DC and military mail.
This tuple is lazily generated and may not work as expected in all cases due to tuple optimizations in the Python interpreter which do not account for lazily generated tuples. For example:
STATE_CHOICES + ('XX', _('Select a State'))
should work as expected, but:
('XX', _('Select a State')) + STATE_CHOICES
may throw:
TypeError: can only concatenate tuple (not "proxy") to tuple
due to a Python optimization that causes the concatenation to occur before STATE_CHOICES has been lazily generated. To work around these issues, you can use a slice index (
[:]
) to force the generation of STATE_CHOICES before any other operations are processed by the Python interpreter:('XX', _('Select a State')) + STATE_CHOICES[:]
-
localflavor.us.us_states.
USPS_CHOICES
= CONTIGUOUS_STATES + NON_CONTIGUOUS_STATES + US_TERRITORIES + ARMED_FORCES_STATES + COFA_STATES¶ All US Postal Service locations.
This tuple is lazily generated and may not work as expected in all cases due to tuple optimizations in the Python interpreter which do not account for lazily generated tuples. For example:
USPS_CHOICES + ('XX', _('Select a State'))
should work as expected, but:
('XX', _('Select a State')) + USPS_CHOICES
may throw:
TypeError: can only concatenate tuple (not "proxy") to tuple
due to a Python optimization that causes the concatenation to occur before USPS_CHOICES has been lazily generated. To work around these issues, you can use a slice index (
[:]
) to force the generation of USPS_CHOICES before any other operations are processed by the Python interpreter:('XX', _('Select a State')) + USPS_CHOICES[:]
-
localflavor.us.us_states.
STATES_NORMALIZED
= {'northern mariana islands': 'MP', 'nv': 'NV', 'nev': 'NV', 'n mex': 'NM', 'deleware': 'DE', 'wi': 'WI', 'kans': 'KS', 'mont': 'MT', 'ariz': 'AZ', 'fla': 'FL', 'wv': 'WV', 'new hampshire': 'NH', 'mo': 'MO', 'ri': 'RI', 'viginia': 'VA', 'mp': 'MP', 'ae': 'AE', 'del': 'DE', 'florida': 'FL', 'tennessee': 'TN', 'oklahoma': 'OK', 'ny': 'NY', 'texas': 'TX', 'tex': 'TX', 'marianas islands of the pacific': 'MP', 'massachussetts': 'MA', 'miss': 'MS', 'aa': 'AA', 'virgina': 'VA', 'n m': 'NM', 'ne': 'NE', 'vi': 'VI', 'sd': 'SD', 'ak': 'AK', 'district of columbia': 'DC', 'il': 'IL', 'nj': 'NJ', 'maine': 'ME', 'mich': 'MI', 'ia': 'IA', 'georgia': 'GA', 'ky': 'KY', 'california': 'CA', 'in': 'IN', 'american samao': 'AS', 'pennsylvania': 'PA', 'rhode island': 'RI', 'mississippi': 'MS', 'mass': 'MA', 'mi': 'MI', 'tenn': 'TN', 'md': 'MD', 'new york': 'NY', 'ct': 'CT', 'illinois': 'IL', 'mt': 'MT', 'as': 'AS', 'iowa': 'IA', 'pa': 'PA', 'guam': 'GU', 'w va': 'WV', 'south carolina': 'SC', 'calf': 'CA', 'co': 'CO', 'arkansas': 'AR', 'tx': 'TX', 'washington': 'WA', 'va': 'VA', 'nc': 'NC', 'hawaii': 'HI', 'dc': 'DC', 'north carolina': 'NC', 'nm': 'NM', 's dak': 'SD', 'ark': 'AR', 'new jersey': 'NJ', 'michigan': 'MI', 'me': 'ME', 'ar': 'AR', 'kansas': 'KS', 'ca': 'CA', 'kentucky': 'KY', 'massachusetts': 'MA', 'marianas islands': 'MP', 'vermont': 'VT', 'marinas islands of the pacific': 'MP', 'al': 'AL', 'or': 'OR', 'colorado': 'CO', 'ohio': 'OH', 'nebraska': 'NE', 'ma': 'MA', 'us virgin islands': 'VI', 'nh': 'NH', 'penn': 'PA', 'oreg': 'OR', 'tn': 'TN', 'minnesota': 'MN', 'calif': 'CA', 'fl': 'FL', 'louisiana': 'LA', 'de': 'DE', 'sdak': 'SD', 'wash': 'WA', 'alaska': 'AK', 'pr': 'PR', 'la': 'LA', 'ill': 'IL', 'new mexico': 'NM', 'utah': 'UT', 'conn': 'CT', 'hi': 'HI', 'vt': 'VT', 'nebr': 'NE', 'neb': 'NE', 'montana': 'MT', 'south dakota': 'SD', 'arizona': 'AZ', 'wva': 'WV', 'mn': 'MN', 'ut': 'UT', 'ms': 'MS', 'north dakota': 'ND', 'nmex': 'NM', 'wisc': 'WI', 'ap': 'AP', 'wy': 'WY', 'puerto rico': 'PR', 'maryland': 'MD', 'virginia': 'VA', 'n dak': 'ND', 'territory of hawaii': 'HI', 'id': 'ID', 'nevada': 'NV', 'american samoa': 'AS', 'delaware': 'DE', 'alabama': 'AL', 'okla': 'OK', 'colo': 'CO', 'kan': 'KS', 'ks': 'KS', 'wyo': 'WY', 'az': 'AZ', 'virgin islands': 'VI', 'ok': 'OK', 'connecticut': 'CT', 'n h': 'NH', 'missouri': 'MO', 'ga': 'GA', 'wisconsin': 'WI', 'west virginia': 'WV', 'ala': 'AL', 'oh': 'OH', 'oregon': 'OR', 'sc': 'SC', 'wyoming': 'WY', 'usvi': 'VI', 'nd': 'ND', 'gu': 'GU', 'wis': 'WI', 'indiana': 'IN', 'minn': 'MN', 'ore': 'OR', 'idaho': 'ID', 'ind': 'IN', 'n j': 'NJ', 'n d': 'ND', 'wa': 'WA'}¶ Normalized versions of state names