ColdCore/utils/select.py

43 lines
1.1 KiB
Python
Raw Normal View History

2016-07-12 14:24:19 +00:00
import pycountry
TShirts = [
"XS",
"S",
"M",
"L",
"XL",
"XXL"
]
Backgrounds = [
("elementary", "Elementary School Student"),
("high", "High School Student"),
("university", "University Student"),
("teacher", "Teacher"),
("professional", "Security Professional"),
("hobbyist", "CTF Hobbyist(non-student)"),
("other", "Other")
]
BackgroundKeys = [x[0] for x in Backgrounds]
Countries = [(country.alpha_3, country.name) for country in pycountry.countries]
2016-07-12 14:24:19 +00:00
Countries = (sorted(Countries, key=lambda x: "0" if x[1] == "Iceland" else x[1]))
CountryKeys = [x[0] for x in Countries]
def genoption(arr, selected=None, header=None):
s = ""
if header is not None:
s += header
for val in arr:
if isinstance(val, tuple):
val, name = val
else:
name = val
if selected is not None and val == selected:
s += ('<option value="%s" selected>%s</option>' % (val, name))
else:
s += ('<option value="%s">%s</option>' % (val, name))
return s