| 1 |
from Entry import * |
|---|
| 2 |
|
|---|
| 3 |
ISO_3166 = { |
|---|
| 4 |
"AD" : "Andorra", |
|---|
| 5 |
"AE" : "United Arab Emirates", |
|---|
| 6 |
"AF" : "Afghanistan", |
|---|
| 7 |
"AG" : "Antigua and Barbuda", |
|---|
| 8 |
"AI" : "Anguilla", |
|---|
| 9 |
"AL" : "Albania", |
|---|
| 10 |
"AM" : "Armenia", |
|---|
| 11 |
"AN" : "Netherlands Antilles", |
|---|
| 12 |
"AO" : "Angola", |
|---|
| 13 |
"AR" : "Argentina", |
|---|
| 14 |
"AS" : "American Samoa", |
|---|
| 15 |
"AT" : "Austria", |
|---|
| 16 |
"AU" : "Australia", |
|---|
| 17 |
"AW" : "Aruba", |
|---|
| 18 |
"AX" : "Aland Islands", |
|---|
| 19 |
"AZ" : "Azerbaijan", |
|---|
| 20 |
"BA" : "Bosnia & Herzegovina", |
|---|
| 21 |
"BB" : "Barbados", |
|---|
| 22 |
"BD" : "Bangladesh", |
|---|
| 23 |
"BE" : "Belgium", |
|---|
| 24 |
"BF" : "Burkina Faso", |
|---|
| 25 |
"BG" : "Bulgaria", |
|---|
| 26 |
"BH" : "Bahrain", |
|---|
| 27 |
"BJ" : "Benin", |
|---|
| 28 |
"BM" : "Bermuda", |
|---|
| 29 |
"BN" : "Brunei Darussalam", |
|---|
| 30 |
"BO" : "Bolivia", |
|---|
| 31 |
"BR" : "Brazil", |
|---|
| 32 |
"BS" : "Bahamas", |
|---|
| 33 |
"BT" : "Bhutan", |
|---|
| 34 |
"BV" : "Bouvet Island", |
|---|
| 35 |
"BW" : "Botswana", |
|---|
| 36 |
"BY" : "Belarus", |
|---|
| 37 |
"BZ" : "Belize", |
|---|
| 38 |
"CA" : "Canada", |
|---|
| 39 |
"CC" : "Cocos (Keeling) Islands", |
|---|
| 40 |
"CD" : "Republic of the Congo", |
|---|
| 41 |
"CF" : "Central African Republic", |
|---|
| 42 |
"CG" : "Congo", |
|---|
| 43 |
"CH" : "Switzerland", |
|---|
| 44 |
"CI" : "Cote D'Ivoire", |
|---|
| 45 |
"CK" : "Cook Islands", |
|---|
| 46 |
"CL" : "Chile", |
|---|
| 47 |
"CM" : "Cameroon", |
|---|
| 48 |
"CN" : "China", |
|---|
| 49 |
"CO" : "Colombia", |
|---|
| 50 |
"CR" : "Costa Rica", |
|---|
| 51 |
"CU" : "Cuba", |
|---|
| 52 |
"CV" : "Cape Verde", |
|---|
| 53 |
"CX" : "Christmas Island", |
|---|
| 54 |
"CY" : "Cyprus", |
|---|
| 55 |
"CZ" : "Czech Republic", |
|---|
| 56 |
"DE" : "Germany", |
|---|
| 57 |
"DJ" : "Djibouti", |
|---|
| 58 |
"DK" : "Denmark", |
|---|
| 59 |
"DM" : "Dominica", |
|---|
| 60 |
"DO" : "Dominican Republic", |
|---|
| 61 |
"DZ" : "Algeria", |
|---|
| 62 |
"EC" : "Ecuador", |
|---|
| 63 |
"EE" : "Estonia", |
|---|
| 64 |
"EG" : "Egypt", |
|---|
| 65 |
"EH" : "Western Sahara", |
|---|
| 66 |
"ER" : "Eritrea", |
|---|
| 67 |
"ES" : "Spain", |
|---|
| 68 |
"ET" : "Ethiopia", |
|---|
| 69 |
"FI" : "Finland", |
|---|
| 70 |
"FJ" : "Fiji", |
|---|
| 71 |
"FK" : "Malvinas", |
|---|
| 72 |
"FM" : "Micronesia, States of", |
|---|
| 73 |
"FO" : "Faroe Islands", |
|---|
| 74 |
"FR" : "France", |
|---|
| 75 |
"GA" : "Gabon", |
|---|
| 76 |
"GB" : "United Kingdom", |
|---|
| 77 |
"GD" : "Grenada", |
|---|
| 78 |
"GE" : "Georgia", |
|---|
| 79 |
"GF" : "French Guiana", |
|---|
| 80 |
"GH" : "Ghana", |
|---|
| 81 |
"GI" : "Gibraltar", |
|---|
| 82 |
"GL" : "Greenland", |
|---|
| 83 |
"GM" : "Gambia", |
|---|
| 84 |
"GN" : "Guinea", |
|---|
| 85 |
"GP" : "Guadeloupe", |
|---|
| 86 |
"GQ" : "Equatorial Guinea", |
|---|
| 87 |
"GR" : "Greece", |
|---|
| 88 |
"GS" : "South Georgia", |
|---|
| 89 |
"GT" : "Guatemala", |
|---|
| 90 |
"GU" : "Guam", |
|---|
| 91 |
"GW" : "Guinea-Bissau", |
|---|
| 92 |
"GY" : "Guyana", |
|---|
| 93 |
"HK" : "Hong Kong", |
|---|
| 94 |
"HM" : "Heard & McDonald", |
|---|
| 95 |
"HN" : "Honduras", |
|---|
| 96 |
"HR" : "Croatia", |
|---|
| 97 |
"HT" : "Haiti", |
|---|
| 98 |
"HU" : "Hungary", |
|---|
| 99 |
"ID" : "Indonesia", |
|---|
| 100 |
"IE" : "Ireland", |
|---|
| 101 |
"IL" : "Israel", |
|---|
| 102 |
"IN" : "India", |
|---|
| 103 |
"IO" : "British Indian", |
|---|
| 104 |
"IQ" : "Iraq", |
|---|
| 105 |
"IR" : "Iran, Republic of", |
|---|
| 106 |
"IS" : "Iceland", |
|---|
| 107 |
"IT" : "Italy", |
|---|
| 108 |
"JM" : "Jamaica", |
|---|
| 109 |
"JO" : "Jordan", |
|---|
| 110 |
"JP" : "Japan", |
|---|
| 111 |
"KE" : "Kenya", |
|---|
| 112 |
"KG" : "Kyrgyzstan", |
|---|
| 113 |
"KH" : "Cambodia", |
|---|
| 114 |
"KI" : "Kiribati", |
|---|
| 115 |
"KM" : "Comoros", |
|---|
| 116 |
"KN" : "Saint Kitts and Nevis", |
|---|
| 117 |
"KP" : "Korea, Republic of", |
|---|
| 118 |
"KR" : "Korea, Republic of", |
|---|
| 119 |
"KW" : "Kuwait", |
|---|
| 120 |
"KY" : "Cayman Islands", |
|---|
| 121 |
"KZ" : "Kazakhstan", |
|---|
| 122 |
"LA" : "Lao, Republic", |
|---|
| 123 |
"LB" : "Lebanon", |
|---|
| 124 |
"LC" : "Saint Lucia", |
|---|
| 125 |
"LI" : "Liechtenstein", |
|---|
| 126 |
"LK" : "Sri Lanka", |
|---|
| 127 |
"LR" : "Liberia", |
|---|
| 128 |
"LS" : "Lesotho", |
|---|
| 129 |
"LT" : "Lithuania", |
|---|
| 130 |
"LU" : "Luxembourg", |
|---|
| 131 |
"LV" : "Latvia", |
|---|
| 132 |
"LY" : "Libyan Arab Jamahiriya", |
|---|
| 133 |
"MA" : "Morocco", |
|---|
| 134 |
"MC" : "Monaco", |
|---|
| 135 |
"MD" : "Moldova, Republic of", |
|---|
| 136 |
"ME" : "Montenegro", |
|---|
| 137 |
"MG" : "Madagascar", |
|---|
| 138 |
"MH" : "Marshall Islands", |
|---|
| 139 |
"MK" : "Macedonia", |
|---|
| 140 |
"ML" : "Mali", |
|---|
| 141 |
"MM" : "Myanmar", |
|---|
| 142 |
"MN" : "Mongolia", |
|---|
| 143 |
"MO" : "Macau", |
|---|
| 144 |
"MP" : "N. Mariana Islands", |
|---|
| 145 |
"MQ" : "Martinique", |
|---|
| 146 |
"MR" : "Mauritania", |
|---|
| 147 |
"MS" : "Montserrat", |
|---|
| 148 |
"MT" : "Malta", |
|---|
| 149 |
"MU" : "Mauritius", |
|---|
| 150 |
"MV" : "Maldives", |
|---|
| 151 |
"MW" : "Malawi", |
|---|
| 152 |
"MX" : "Mexico", |
|---|
| 153 |
"MY" : "Malaysia", |
|---|
| 154 |
"MZ" : "Mozambique", |
|---|
| 155 |
"NA" : "Namibia", |
|---|
| 156 |
"NC" : "New Caledonia", |
|---|
| 157 |
"NE" : "Niger", |
|---|
| 158 |
"NF" : "Norfolk Island", |
|---|
| 159 |
"NG" : "Nigeria", |
|---|
| 160 |
"NI" : "Nicaragua", |
|---|
| 161 |
"NL" : "Netherlands", |
|---|
| 162 |
"NO" : "Norway", |
|---|
| 163 |
"NP" : "Nepal", |
|---|
| 164 |
"NR" : "Nauru", |
|---|
| 165 |
"NU" : "Niue", |
|---|
| 166 |
"NZ" : "New Zealand", |
|---|
| 167 |
"OM" : "Oman", |
|---|
| 168 |
"PA" : "Panama", |
|---|
| 169 |
"PE" : "Peru", |
|---|
| 170 |
"PF" : "French Polynesia", |
|---|
| 171 |
"PG" : "Papua New Guinea", |
|---|
| 172 |
"PH" : "Philippines", |
|---|
| 173 |
"PK" : "Pakistan", |
|---|
| 174 |
"PL" : "Poland", |
|---|
| 175 |
"PM" : "S. Pierre & Miquelon", |
|---|
| 176 |
"PN" : "Pitcairn Islands", |
|---|
| 177 |
"PR" : "Puerto Rico", |
|---|
| 178 |
"PS" : "Palestinian Territory", |
|---|
| 179 |
"PT" : "Portugal", |
|---|
| 180 |
"PW" : "Palau", |
|---|
| 181 |
"PY" : "Paraguay", |
|---|
| 182 |
"QA" : "Qatar", |
|---|
| 183 |
"RE" : "Reunion", |
|---|
| 184 |
"RO" : "Romania", |
|---|
| 185 |
"RS" : "Serbia", |
|---|
| 186 |
"RU" : "Russian Federation", |
|---|
| 187 |
"RW" : "Rwanda", |
|---|
| 188 |
"SA" : "Saudi Arabia", |
|---|
| 189 |
"SB" : "Solomon Islands", |
|---|
| 190 |
"SC" : "Seychelles", |
|---|
| 191 |
"SD" : "Sudan", |
|---|
| 192 |
"SE" : "Sweden", |
|---|
| 193 |
"SG" : "Singapore", |
|---|
| 194 |
"SH" : "Saint Helena", |
|---|
| 195 |
"SI" : "Slovenia", |
|---|
| 196 |
"SJ" : "Svalbard and Jan Mayen", |
|---|
| 197 |
"SK" : "Slovakia", |
|---|
| 198 |
"SL" : "Sierra Leone", |
|---|
| 199 |
"SM" : "San Marino", |
|---|
| 200 |
"SN" : "Senegal", |
|---|
| 201 |
"SO" : "Somalia", |
|---|
| 202 |
"SR" : "Suriname", |
|---|
| 203 |
"ST" : "Sao Tome & Principe", |
|---|
| 204 |
"SV" : "El Salvador", |
|---|
| 205 |
"SY" : "Syrian Arab Republic", |
|---|
| 206 |
"SZ" : "Swaziland", |
|---|
| 207 |
"TC" : "Turks & Caicos Islands", |
|---|
| 208 |
"TD" : "Chad", |
|---|
| 209 |
"TF" : "French S. Territories", |
|---|
| 210 |
"TG" : "Togo", |
|---|
| 211 |
"TH" : "Thailand", |
|---|
| 212 |
"TJ" : "Tajikistan", |
|---|
| 213 |
"TK" : "Tokelau", |
|---|
| 214 |
"TL" : "Timor-Leste", |
|---|
| 215 |
"TM" : "Turkmenistan", |
|---|
| 216 |
"TN" : "Tunisia", |
|---|
| 217 |
"TO" : "Tonga", |
|---|
| 218 |
"TR" : "Turkey", |
|---|
| 219 |
"TT" : "Trinidad and Tobago", |
|---|
| 220 |
"TV" : "Tuvalu", |
|---|
| 221 |
"TW" : "Taiwan", |
|---|
| 222 |
"TZ" : "Tanzania, Republic of", |
|---|
| 223 |
"UA" : "Ukraine", |
|---|
| 224 |
"UG" : "Uganda", |
|---|
| 225 |
"UM" : "US Outlying Islands", |
|---|
| 226 |
"US" : "United States", |
|---|
| 227 |
"UY" : "Uruguay", |
|---|
| 228 |
"UZ" : "Uzbekistan", |
|---|
| 229 |
"VA" : "Vatican City State", |
|---|
| 230 |
"VC" : "S. Vincent & Grenadines", |
|---|
| 231 |
"VE" : "Venezuela", |
|---|
| 232 |
"VG" : "Virgin Islands, British", |
|---|
| 233 |
"VI" : "Virgin Islands, U.S.", |
|---|
| 234 |
"VN" : "Vietnam", |
|---|
| 235 |
"VU" : "Vanuatu", |
|---|
| 236 |
"WF" : "Wallis and Futuna", |
|---|
| 237 |
"WS" : "Samoa", |
|---|
| 238 |
"YE" : "Yemen", |
|---|
| 239 |
"YT" : "Mayotte", |
|---|
| 240 |
"ZA" : "South Africa", |
|---|
| 241 |
"ZM" : "Zambia", |
|---|
| 242 |
"ZW" : "Zimbabwe" |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
EXTRA_OPTIONS = [ |
|---|
| 246 |
("EU", "Europe", "europeanunion.png"), |
|---|
| 247 |
("AP", "Asia/Pacific Region"), |
|---|
| 248 |
("AQ", "Antarctica"), |
|---|
| 249 |
("BI", "Burundi"), |
|---|
| 250 |
("BL", "Saint Barthelemy"), |
|---|
| 251 |
("FX", "France, Metropolitan"), |
|---|
| 252 |
("GG", "Guernsey"), |
|---|
| 253 |
("IM", "Isle of Man"), |
|---|
| 254 |
("JE", "Jersey"), |
|---|
| 255 |
("MF", "Saint Martin"), |
|---|
| 256 |
("A1", "Anonymous Proxy"), |
|---|
| 257 |
("A2", "Satellite Provider"), |
|---|
| 258 |
("O1", "Other") |
|---|
| 259 |
] |
|---|
| 260 |
|
|---|
| 261 |
ADD_FLAGS_TO_KEY_JS = """ |
|---|
| 262 |
<script type="text/javascript"> |
|---|
| 263 |
function flags_add_to_key (options_id, cfg_key, cfg_key_value, url) |
|---|
| 264 |
{ |
|---|
| 265 |
var thisselect = get_by_id_and_class (options_id, 'select'); |
|---|
| 266 |
var options = thisselect.options; |
|---|
| 267 |
var selected = options[options.selectedIndex].value; |
|---|
| 268 |
var value = cfg_key_value + "," + selected; |
|---|
| 269 |
var post = cfg_key + "=" + value; |
|---|
| 270 |
|
|---|
| 271 |
/* Do not add the country if it's already in the list |
|---|
| 272 |
*/ |
|---|
| 273 |
if (cfg_key_value.indexOf(selected) >= 0) |
|---|
| 274 |
return; |
|---|
| 275 |
|
|---|
| 276 |
jQuery.post (url, post, |
|---|
| 277 |
function (data, textStatus) { |
|---|
| 278 |
window.location.reload(); |
|---|
| 279 |
} |
|---|
| 280 |
); |
|---|
| 281 |
} |
|---|
| 282 |
</script> |
|---|
| 283 |
""" |
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
class OptionFlags: |
|---|
| 287 |
def __init__ (self, name, *args, **kwargs): |
|---|
| 288 |
self._name = name |
|---|
| 289 |
self._kwargs = kwargs |
|---|
| 290 |
|
|---|
| 291 |
def _render_option (self, code, name, icon): |
|---|
| 292 |
if icon: |
|---|
| 293 |
style = 'style="background-image:url(/static/images/flags/%s); background-repeat:no-repeat; background-position:bottom right;" ' % (icon) |
|---|
| 294 |
else: |
|---|
| 295 |
style = "" |
|---|
| 296 |
|
|---|
| 297 |
return '\t<option %svalue="%s">%s - %s</option>\n' % (style, code, code, name) |
|---|
| 298 |
|
|---|
| 299 |
def __str__ (self): |
|---|
| 300 |
props = 'id="%s" name="%s"' % (self._name, self._name) |
|---|
| 301 |
|
|---|
| 302 |
for prop in self._kwargs: |
|---|
| 303 |
props += ' %s="%s"' % (prop, self._kwargs[prop]) |
|---|
| 304 |
|
|---|
| 305 |
codes = ISO_3166.keys() |
|---|
| 306 |
codes.sort() |
|---|
| 307 |
|
|---|
| 308 |
txt = '<select %s>\n' % (props) |
|---|
| 309 |
txt += ' <optgroup label="Countries">' |
|---|
| 310 |
for code in codes: |
|---|
| 311 |
txt += self._render_option (code, ISO_3166[code], "%s.png"%(code)) |
|---|
| 312 |
txt += ' </optgroup>' |
|---|
| 313 |
|
|---|
| 314 |
txt += ' <optgroup label="Extra">' |
|---|
| 315 |
for entry in EXTRA_OPTIONS: |
|---|
| 316 |
icon = None |
|---|
| 317 |
if len(entry) == 2: |
|---|
| 318 |
code, name = entry |
|---|
| 319 |
else: |
|---|
| 320 |
code, name, icon = entry |
|---|
| 321 |
txt += self._render_option (code, name, icon) |
|---|
| 322 |
txt += ' </optgroup>' |
|---|
| 323 |
txt += '</select>\n' |
|---|
| 324 |
|
|---|
| 325 |
return txt |
|---|