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