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 formatXXX-XXX-XXXX
).
-
class
localflavor.us.models.
USPostalCodeField
(*args, **kwargs)[source]¶ ” A model field that forms represent as a
USPSSelect`
field and stores the two-letter U.S. Postal Service abbreviation in the database.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 forms represent as
forms.USSocialSecurityNumberField
and stores in the formatXXX-XX-XXXX
.New in version 1.1.
-
class
localflavor.us.models.
USStateField
(*args, **kwargs)[source]¶ A model field that forms represent as a
forms.USStateField
field and stores the two-letter U.S. state abbreviation in the database.
-
class
localflavor.us.models.
USZipCodeField
(*args, **kwargs)[source]¶ A model field that forms represent as a
USZipCodeField
field and stores the U.S. ZIP code in the database.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.
US_STATES
= (('AL', 'Alabama'), ('AK', 'Alaska'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('HI', 'Hawaii'), ('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'))¶ All 50 states, plus the District of Columbia.
-
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.
STATE_CHOICES
= (('AL', 'Alabama'), ('AK', 'Alaska'), ('AS', 'American Samoa'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('AA', 'Armed Forces Americas'), ('AE', 'Armed Forces Europe'), ('AP', 'Armed Forces Pacific'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('GU', 'Guam'), ('HI', 'Hawaii'), ('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'), ('MP', 'Northern Mariana Islands'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA', 'Pennsylvania'), ('PR', 'Puerto Rico'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VI', 'Virgin Islands'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))¶ All US states and territories plus DC and military mail.
-
localflavor.us.us_states.
USPS_CHOICES
= (('AL', 'Alabama'), ('AK', 'Alaska'), ('AS', 'American Samoa'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('AA', 'Armed Forces Americas'), ('AE', 'Armed Forces Europe'), ('AP', 'Armed Forces Pacific'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FM', 'Federated States of Micronesia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('GU', 'Guam'), ('HI', 'Hawaii'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MH', 'Marshall Islands'), ('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'), ('MP', 'Northern Mariana Islands'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PW', 'Palau'), ('PA', 'Pennsylvania'), ('PR', 'Puerto Rico'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VI', 'Virgin Islands'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))¶ All US Postal Service locations.
-
localflavor.us.us_states.
STATES_NORMALIZED
= {'mt': 'MT', 'del': 'DE', 'alabama': 'AL', 'idaho': 'ID', 'mich': 'MI', 'tennessee': 'TN', 'vt': 'VT', 'calif': 'CA', 'us virgin islands': 'VI', 'ms': 'MS', 'mp': 'MP', 'delaware': 'DE', 'kan': 'KS', 'fla': 'FL', 'west virginia': 'WV', 'in': 'IN', 'ak': 'AK', 'massachusetts': 'MA', 'montana': 'MT', 'minnesota': 'MN', 'arizona': 'AZ', 'nev': 'NV', 'maryland': 'MD', 'south carolina': 'SC', 'md': 'MD', 'aa': 'AA', 'indiana': 'IN', 'arkansas': 'AR', 'louisiana': 'LA', 'me': 'ME', 'n h': 'NH', 'sdak': 'SD', 'mississippi': 'MS', 'kansas': 'KS', 'mn': 'MN', 'usvi': 'VI', 'id': 'ID', 'sc': 'SC', 'nd': 'ND', 'mi': 'MI', 'hawaii': 'HI', 'de': 'DE', 'minn': 'MN', 'colorado': 'CO', 'ind': 'IN', 'oklahoma': 'OK', 'viginia': 'VA', 'nv': 'NV', 'hi': 'HI', 'illinois': 'IL', 'al': 'AL', 'nj': 'NJ', 'pa': 'PA', 'california': 'CA', 'ct': 'CT', 'virginia': 'VA', 'wa': 'WA', 'ia': 'IA', 'ae': 'AE', 'ri': 'RI', 'ohio': 'OH', 'tex': 'TX', 'ark': 'AR', 'n m': 'NM', 'colo': 'CO', 'az': 'AZ', 'guam': 'GU', 'ok': 'OK', 'kentucky': 'KY', 'new york': 'NY', 'pr': 'PR', 'ariz': 'AZ', 'wv': 'WV', 'wy': 'WY', 'connecticut': 'CT', 'utah': 'UT', 'american samao': 'AS', 'ga': 'GA', 'ca': 'CA', 'new jersey': 'NJ', 'georgia': 'GA', 'calf': 'CA', 'il': 'IL', 'mont': 'MT', 'ks': 'KS', 'fl': 'FL', 'sd': 'SD', 'massachussetts': 'MA', 'dc': 'DC', 'oregon': 'OR', 'marianas islands': 'MP', 'tn': 'TN', 'florida': 'FL', 'nm': 'NM', 'ill': 'IL', 'conn': 'CT', 'neb': 'NE', 'wisc': 'WI', 'ny': 'NY', 'territory of hawaii': 'HI', 'nebraska': 'NE', 'nh': 'NH', 'ma': 'MA', 'oh': 'OH', 'w va': 'WV', 'washington': 'WA', 'district of columbia': 'DC', 'tx': 'TX', 'michigan': 'MI', 'marianas islands of the pacific': 'MP', 'penn': 'PA', 'ne': 'NE', 'texas': 'TX', 'ap': 'AP', 'pennsylvania': 'PA', 'nmex': 'NM', 'or': 'OR', 'mass': 'MA', 'vi': 'VI', 'tenn': 'TN', 'rhode island': 'RI', 'wyo': 'WY', 'kans': 'KS', 'marinas islands of the pacific': 'MP', 'puerto rico': 'PR', 'okla': 'OK', 'wi': 'WI', 'nevada': 'NV', 'n dak': 'ND', 'virgin islands': 'VI', 'ore': 'OR', 'nebr': 'NE', 'iowa': 'IA', 'mo': 'MO', 'vermont': 'VT', 'n d': 'ND', 'co': 'CO', 'nc': 'NC', 'northern mariana islands': 'MP', 'as': 'AS', 'north carolina': 'NC', 'ut': 'UT', 'ky': 'KY', 'oreg': 'OR', 'n mex': 'NM', 'la': 'LA', 's dak': 'SD', 'n j': 'NJ', 'missouri': 'MO', 'virgina': 'VA', 'alaska': 'AK', 'miss': 'MS', 'wash': 'WA', 'new mexico': 'NM', 'deleware': 'DE', 'north dakota': 'ND', 'wisconsin': 'WI', 'new hampshire': 'NH', 'ar': 'AR', 'wva': 'WV', 'wyoming': 'WY', 'wis': 'WI', 'va': 'VA', 'maine': 'ME', 'south dakota': 'SD', 'gu': 'GU', 'ala': 'AL', 'american samoa': 'AS'}¶ Normalized versions of state names