| 1 | from django.utils.translation import ugettext as _ |
| 2 | from django.core.exceptions import ValidationError |
| 3 | from django.conf import settings |
| 4 | |
| 5 | # Countries list - ISO 3166-1 |
| 6 | # http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 |
| 7 | |
| 8 | COUNTRIES = ( |
| 9 | ('AD', _('Andorra')), |
| 10 | ('AE', _('United Arab Emirates')), |
| 11 | ('AF', _('Afghanistan')), |
| 12 | ('AG', _('Antigua & Barbuda')), |
| 13 | ('AI', _('Anguilla')), |
| 14 | ('AL', _('Albania')), |
| 15 | ('AM', _('Armenia')), |
| 16 | ('AN', _('Netherlands Antilles')), |
| 17 | ('AO', _('Angola')), |
| 18 | ('AQ', _('Antarctica')), |
| 19 | ('AR', _('Argentina')), |
| 20 | ('AS', _('American Samoa')), |
| 21 | ('AT', _('Austria')), |
| 22 | ('AU', _('Australia')), |
| 23 | ('AW', _('Aruba')), |
| 24 | ('AZ', _('Azerbaijan')), |
| 25 | ('BA', _('Bosnia and Herzegovina')), |
| 26 | ('BB', _('Barbados')), |
| 27 | ('BD', _('Bangladesh')), |
| 28 | ('BE', _('Belgium')), |
| 29 | ('BF', _('Burkina Faso')), |
| 30 | ('BG', _('Bulgaria')), |
| 31 | ('BH', _('Bahrain')), |
| 32 | ('BI', _('Burundi')), |
| 33 | ('BJ', _('Benin')), |
| 34 | ('BM', _('Bermuda')), |
| 35 | ('BN', _('Brunei Darussalam')), |
| 36 | ('BO', _('Bolivia')), |
| 37 | ('BR', _('Brazil')), |
| 38 | ('BS', _('Bahama')), |
| 39 | ('BT', _('Bhutan')), |
| 40 | ('BV', _('Bouvet Island')), |
| 41 | ('BW', _('Botswana')), |
| 42 | ('BY', _('Belarus')), |
| 43 | ('BZ', _('Belize')), |
| 44 | ('CA', _('Canada')), |
| 45 | ('CC', _('Cocos (Keeling) Islands')), |
| 46 | ('CF', _('Central African Republic')), |
| 47 | ('CG', _('Congo')), |
| 48 | ('CH', _('Switzerland')), |
| 49 | ('CI', _('Ivory Coast')), |
| 50 | ('CK', _('Cook Iislands')), |
| 51 | ('CL', _('Chile')), |
| 52 | ('CM', _('Cameroon')), |
| 53 | ('CN', _('China')), |
| 54 | ('CO', _('Colombia')), |
| 55 | ('CR', _('Costa Rica')), |
| 56 | ('CU', _('Cuba')), |
| 57 | ('CV', _('Cape Verde')), |
| 58 | ('CX', _('Christmas Island')), |
| 59 | ('CY', _('Cyprus')), |
| 60 | ('CZ', _('Czech Republic')), |
| 61 | ('DE', _('Germany')), |
| 62 | ('DJ', _('Djibouti')), |
| 63 | ('DK', _('Denmark')), |
| 64 | ('DM', _('Dominica')), |
| 65 | ('DO', _('Dominican Republic')), |
| 66 | ('DZ', _('Algeria')), |
| 67 | ('EC', _('Ecuador')), |
| 68 | ('EE', _('Estonia')), |
| 69 | ('EG', _('Egypt')), |
| 70 | ('EH', _('Western Sahara')), |
| 71 | ('ER', _('Eritrea')), |
| 72 | ('ES', _('Spain')), |
| 73 | ('ET', _('Ethiopia')), |
| 74 | ('FI', _('Finland')), |
| 75 | ('FJ', _('Fiji')), |
| 76 | ('FK', _('Falkland Islands (Malvinas)')), |
| 77 | ('FM', _('Micronesia')), |
| 78 | ('FO', _('Faroe Islands')), |
| 79 | ('FR', _('France')), |
| 80 | ('FX', _('France, Metropolitan')), |
| 81 | ('GA', _('Gabon')), |
| 82 | ('GB', _('United Kingdom (Great Britain)')), |
| 83 | ('GD', _('Grenada')), |
| 84 | ('GE', _('Georgia')), |
| 85 | ('GF', _('French Guiana')), |
| 86 | ('GH', _('Ghana')), |
| 87 | ('GI', _('Gibraltar')), |
| 88 | ('GL', _('Greenland')), |
| 89 | ('GM', _('Gambia')), |
| 90 | ('GN', _('Guinea')), |
| 91 | ('GP', _('Guadeloupe')), |
| 92 | ('GQ', _('Equatorial Guinea')), |
| 93 | ('GR', _('Greece')), |
| 94 | ('GS', _('South Georgia and the South Sandwich Islands')), |
| 95 | ('GT', _('Guatemala')), |
| 96 | ('GU', _('Guam')), |
| 97 | ('GW', _('Guinea-Bissau')), |
| 98 | ('GY', _('Guyana')), |
| 99 | ('HK', _('Hong Kong')), |
| 100 | ('HM', _('Heard & McDonald Islands')), |
| 101 | ('HN', _('Honduras')), |
| 102 | ('HR', _('Croatia')), |
| 103 | ('HT', _('Haiti')), |
| 104 | ('HU', _('Hungary')), |
| 105 | ('ID', _('Indonesia')), |
| 106 | ('IE', _('Ireland')), |
| 107 | ('IL', _('Israel')), |
| 108 | ('IN', _('India')), |
| 109 | ('IO', _('British Indian Ocean Territory')), |
| 110 | ('IQ', _('Iraq')), |
| 111 | ('IR', _('Islamic Republic of Iran')), |
| 112 | ('IS', _('Iceland')), |
| 113 | ('IT', _('Italy')), |
| 114 | ('JM', _('Jamaica')), |
| 115 | ('JO', _('Jordan')), |
| 116 | ('JP', _('Japan')), |
| 117 | ('KE', _('Kenya')), |
| 118 | ('KG', _('Kyrgyzstan')), |
| 119 | ('KH', _('Cambodia')), |
| 120 | ('KI', _('Kiribati')), |
| 121 | ('KM', _('Comoros')), |
| 122 | ('KN', _('St. Kitts and Nevis')), |
| 123 | ('KP', _('Korea, Democratic People\'s Republic of')), |
| 124 | ('KR', _('Korea, Republic of')), |
| 125 | ('KW', _('Kuwait')), |
| 126 | ('KY', _('Cayman Islands')), |
| 127 | ('KZ', _('Kazakhstan')), |
| 128 | ('LA', _('Lao People\'s Democratic Republic')), |
| 129 | ('LB', _('Lebanon')), |
| 130 | ('LC', _('Saint Lucia')), |
| 131 | ('LI', _('Liechtenstein')), |
| 132 | ('LK', _('Sri Lanka')), |
| 133 | ('LR', _('Liberia')), |
| 134 | ('LS', _('Lesotho')), |
| 135 | ('LT', _('Lithuania')), |
| 136 | ('LU', _('Luxembourg')), |
| 137 | ('LV', _('Latvia')), |
| 138 | ('LY', _('Libyan Arab Jamahiriya')), |
| 139 | ('MA', _('Morocco')), |
| 140 | ('MC', _('Monaco')), |
| 141 | ('MD', _('Moldova, Republic of')), |
| 142 | ('MG', _('Madagascar')), |
| 143 | ('MH', _('Marshall Islands')), |
| 144 | ('ML', _('Mali')), |
| 145 | ('MN', _('Mongolia')), |
| 146 | ('MM', _('Myanmar')), |
| 147 | ('MO', _('Macau')), |
| 148 | ('MP', _('Northern Mariana Islands')), |
| 149 | ('MQ', _('Martinique')), |
| 150 | ('MR', _('Mauritania')), |
| 151 | ('MS', _('Monserrat')), |
| 152 | ('MT', _('Malta')), |
| 153 | ('MU', _('Mauritius')), |
| 154 | ('MV', _('Maldives')), |
| 155 | ('MW', _('Malawi')), |
| 156 | ('MX', _('Mexico')), |
| 157 | ('MY', _('Malaysia')), |
| 158 | ('MZ', _('Mozambique')), |
| 159 | ('NA', _('Namibia')), |
| 160 | ('NC', _('New Caledonia')), |
| 161 | ('NE', _('Niger')), |
| 162 | ('NF', _('Norfolk Island')), |
| 163 | ('NG', _('Nigeria')), |
| 164 | ('NI', _('Nicaragua')), |
| 165 | ('NL', _('Netherlands')), |
| 166 | ('NO', _('Norway')), |
| 167 | ('NP', _('Nepal')), |
| 168 | ('NR', _('Nauru')), |
| 169 | ('NU', _('Niue')), |
| 170 | ('NZ', _('New Zealand')), |
| 171 | ('OM', _('Oman')), |
| 172 | ('PA', _('Panama')), |
| 173 | ('PE', _('Peru')), |
| 174 | ('PF', _('French Polynesia')), |
| 175 | ('PG', _('Papua New Guinea')), |
| 176 | ('PH', _('Philippines')), |
| 177 | ('PK', _('Pakistan')), |
| 178 | ('PL', _('Poland')), |
| 179 | ('PM', _('St. Pierre & Miquelon')), |
| 180 | ('PN', _('Pitcairn')), |
| 181 | ('PR', _('Puerto Rico')), |
| 182 | ('PT', _('Portugal')), |
| 183 | ('PW', _('Palau')), |
| 184 | ('PY', _('Paraguay')), |
| 185 | ('QA', _('Qatar')), |
| 186 | ('RE', _('Reunion')), |
| 187 | ('RO', _('Romania')), |
| 188 | ('RU', _('Russian Federation')), |
| 189 | ('RW', _('Rwanda')), |
| 190 | ('SA', _('Saudi Arabia')), |
| 191 | ('SB', _('Solomon Islands')), |
| 192 | ('SC', _('Seychelles')), |
| 193 | ('SD', _('Sudan')), |
| 194 | ('SE', _('Sweden')), |
| 195 | ('SG', _('Singapore')), |
| 196 | ('SH', _('St. Helena')), |
| 197 | ('SI', _('Slovenia')), |
| 198 | ('SJ', _('Svalbard & Jan Mayen Islands')), |
| 199 | ('SK', _('Slovakia')), |
| 200 | ('SL', _('Sierra Leone')), |
| 201 | ('SM', _('San Marino')), |
| 202 | ('SN', _('Senegal')), |
| 203 | ('SO', _('Somalia')), |
| 204 | ('SR', _('Suriname')), |
| 205 | ('ST', _('Sao Tome & Principe')), |
| 206 | ('SV', _('El Salvador')), |
| 207 | ('SY', _('Syrian Arab Republic')), |
| 208 | ('SZ', _('Swaziland')), |
| 209 | ('TC', _('Turks & Caicos Islands')), |
| 210 | ('TD', _('Chad')), |
| 211 | ('TF', _('French Southern Territories')), |
| 212 | ('TG', _('Togo')), |
| 213 | ('TH', _('Thailand')), |
| 214 | ('TJ', _('Tajikistan')), |
| 215 | ('TK', _('Tokelau')), |
| 216 | ('TM', _('Turkmenistan')), |
| 217 | ('TN', _('Tunisia')), |
| 218 | ('TO', _('Tonga')), |
| 219 | ('TP', _('East Timor')), |
| 220 | ('TR', _('Turkey')), |
| 221 | ('TT', _('Trinidad & Tobago')), |
| 222 | ('TV', _('Tuvalu')), |
| 223 | ('TW', _('Taiwan, Province of China')), |
| 224 | ('TZ', _('Tanzania, United Republic of')), |
| 225 | ('UA', _('Ukraine')), |
| 226 | ('UG', _('Uganda')), |
| 227 | ('UM', _('United States Minor Outlying Islands')), |
| 228 | ('US', _('United States of America')), |
| 229 | ('UY', _('Uruguay')), |
| 230 | ('UZ', _('Uzbekistan')), |
| 231 | ('VA', _('Vatican City State (Holy See)')), |
| 232 | ('VC', _('St. Vincent & the Grenadines')), |
| 233 | ('VE', _('Venezuela')), |
| 234 | ('VG', _('British Virgin Islands')), |
| 235 | ('VI', _('United States Virgin Islands')), |
| 236 | ('VN', _('Viet Nam')), |
| 237 | ('VU', _('Vanuatu')), |
| 238 | ('WF', _('Wallis & Futuna Islands')), |
| 239 | ('WS', _('Samoa')), |
| 240 | ('YE', _('Yemen')), |
| 241 | ('YT', _('Mayotte')), |
| 242 | ('YU', _('Yugoslavia')), |
| 243 | ('ZA', _('South Africa')), |
| 244 | ('ZM', _('Zambia')), |
| 245 | ('ZR', _('Zaire')), |
| 246 | ('ZW', _('Zimbabwe')), |
| 247 | ('ZZ', _('Unknown or unspecified country')), |
| 248 | ) |
| 249 | |
| 250 | def isValidLanguage(field_data, all_data): |
| 251 | if not field_data in [lang[0] for lang in settings.LANGUAGES]: |
| 252 | raise ValidationError, _("This value must be in LANGUAGES setting in settings.py module.") |
| 253 | |
| 254 | def isValidCountry(field_data, all_data): |
| 255 | if not field_data in [lang[0] for lang in COUNTRIES]: |
| 256 | raise ValidationError, _("This value must be in COUNTRIES setting in localflavor.generic package.") |