from . import db
from flask import flash
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, PasswordField, TextAreaField, \
IntegerField, DateField, SelectField, RadioField, FormField, HiddenField, \
DateTimeField, BooleanField, FileField
from wtforms.validators import DataRequired, ValidationError, EqualTo, Email, \
Optional, Length
from .data import Category

PROFILE_STATEs = [
  ("", "Select your State/Province"),
  ("AL", "Alabama"),
  ("AK", "Alaska"),
  ("AB", "Alberta"),
  ("AZ", "Arizona"),
  ("AR", "Arkansas"),
  ("BC", "British Columbia"),
  ("CA", "California"),
  ("CO", "Colorado"),
  ("CT", "Connecticut"),
  ("DE", "Delaware"),
  ("FL", "Florida"),
  ("GA", "Georgia"),
  ("HI", "Hawaii"),
  ("ID", "Idaho"),
  ("IL", "Illinois"),
  ("IN", "Indiana"),
  ("IA", "Iowa"),
  ("KS", "Kansas"),
  ("KY", "Kentucky"),
  ("LA", "Louisiana"),
  ("ME", "Maine"),
  ("MB", "Manitoba"),
  ("MD", "Maryland"),
  ("MA", "Massachusetts"),
  ("MI", "Michigan"),
  ("MN", "Minnesota"),
  ("MS", "Mississippi"),
  ("MO", "Missouri"),
  ("MT", "Montana"),
  ("NE", "Nebraska"),
  ("NV", "Nevada"),
  ("NB", "New Brunswick"),
  ("NH", "New Hampshire"),
  ("NJ", "New Jersey"),
  ("NM", "New Mexico"),
  ("NY", "New York"),
  ("NL", "Newfoundland and Labrador"),
  ("NC", "North Carolina"),
  ("ND", "North Dakota"),
  ("NT", "Northwest Territories"),
  ("NS", "Nova Scotia"),
  ("NU", "Nunavut"),
  ("OH", "Ohio"),
  ("OK", "Oklahoma"),
  ("ON", "Ontario"),
  ("OR", "Oregon"),
  ("PA", "Pennsylvania"),
  ("PE", "Prince Edward Island"),
  ("PR", "Puerto Rico"),
  ("QC", "Quebec"),
  ("RI", "Rhode Island"),
  ("SK", "Saskatchewan"),
  ("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"),
  ("YT", "Yukon"),
]

PROFILE_COUNTRYs = [
 ("Select your Country", "Select your Country"),
 ("Afghanistan", "Afghanistan"),
 ("Albania", "Albania"),
 ("Algeria", "Algeria"),
 ("Andorra", "Andorra"),
 ("Angola", "Angola"),
 ("Antigua and Barbuda", "Antigua and Barbuda"),
 ("Argentina", "Argentina"),
 ("Armenia", "Armenia"),
 ("Australia", "Australia"),
 ("Austria", "Austria"),
 ("Azerbaijan", "Azerbaijan"),
 ("Bahamas", "Bahamas"),
 ("Bahrain", "Bahrain"),
 ("Bangladesh", "Bangladesh"),
 ("Barbados", "Barbados"),
 ("Belarus", "Belarus"),
 ("Belgium", "Belgium"),
 ("Belize", "Belize"),
 ("Benin", "Benin"),
 ("Bhutan", "Bhutan"),
 ("Bolivia", "Bolivia"),
 ("Bosnia and Herzegovina", "Bosnia and Herzegovina"),
 ("Botswana", "Botswana"),
 ("Brazil", "Brazil"),
 ("Brunei Darussalam", "Brunei Darussalam"),
 ("Bulgaria", "Bulgaria"),
 ("Burkina Faso", "Burkina Faso"),
 ("Burundi", "Burundi"),
 ("Cabo Verde", "Cabo Verde"),
 ("Cambodia", "Cambodia"),
 ("Cameroon", "Cameroon"),
 ("Canada", "Canada"),
 ("Central African Republic", "Central African Republic"),
 ("Chad", "Chad"),
 ("Chile", "Chile"),
 ("China", "China"),
 ("Colombia", "Colombia"),
 ("Comoros", "Comoros"),
 ("Congo", "Congo"),
 ("Costa Rica", "Costa Rica"),
 ("Croatia", "Croatia"),
 ("Cuba", "Cuba"),
 ("Cyprus", "Cyprus"),
 ("Czech Republic", "Czech Republic"),
 ("Cï¿½te d'Ivoire", "Cï¿½te d'Ivoire"),
 ("Democratic People's Republic of Korea (North Korea)", "Democratic People's Republic of Korea (North Korea)"),
 ("Democratic Republic of the Cong", "Democratic Republic of the Cong"),
 ("Denmark", "Denmark"),
 ("Djibouti", "Djibouti"),
 ("Dominica", "Dominica"),
 ("Dominican Republic", "Dominican Republic"),
 ("Ecuador", "Ecuador"),
 ("Egypt", "Egypt"),
 ("El Salvador", "El Salvador"),
 ("Equatorial Guinea", "Equatorial Guinea"),
 ("Eritrea", "Eritrea"),
 ("Estonia", "Estonia"),
 ("Ethiopia", "Ethiopia"),
 ("Fiji", "Fiji"),
 ("Finland", "Finland"),
 ("France", "France"),
 ("Gabon", "Gabon"),
 ("Gambia", "Gambia"),
 ("Georgia", "Georgia"),
 ("Germany", "Germany"),
 ("Ghana", "Ghana"),
 ("Greece", "Greece"),
 ("Grenada", "Grenada"),
 ("Guatemala", "Guatemala"),
 ("Guinea", "Guinea"),
 ("Guinea-Bissau", "Guinea-Bissau"),
 ("Guyana", "Guyana"),
 ("Haiti", "Haiti"),
 ("Honduras", "Honduras"),
 ("Hungary", "Hungary"),
 ("Iceland", "Iceland"),
 ("India", "India"),
 ("Indonesia", "Indonesia"),
 ("Iran", "Iran"),
 ("Iraq", "Iraq"),
 ("Ireland", "Ireland"),
 ("Israel", "Israel"),
 ("Italy", "Italy"),
 ("Jamaica", "Jamaica"),
 ("Japan", "Japan"),
 ("Jordan", "Jordan"),
 ("Kazakhstan", "Kazakhstan"),
 ("Kenya", "Kenya"),
 ("Kiribati", "Kiribati"),
 ("Kuwait", "Kuwait"),
 ("Kyrgyzstan", "Kyrgyzstan"),
 ("Lao People's Democratic Republic (Laos)", "Lao People's Democratic Republic (Laos)"),
 ("Latvia", "Latvia"),
 ("Lebanon", "Lebanon"),
 ("Lesotho", "Lesotho"),
 ("Liberia", "Liberia"),
 ("Libya", "Libya"),
 ("Liechtenstein", "Liechtenstein"),
 ("Lithuania", "Lithuania"),
 ("Luxembourg", "Luxembourg"),
 ("Macedonia", "Macedonia"),
 ("Madagascar", "Madagascar"),
 ("Malawi", "Malawi"),
 ("Malaysia", "Malaysia"),
 ("Maldives", "Maldives"),
 ("Mali", "Mali"),
 ("Malta", "Malta"),
 ("Marshall Islands", "Marshall Islands"),
 ("Mauritania", "Mauritania"),
 ("Mauritius", "Mauritius"),
 ("Mexico", "Mexico"),
 ("Micronesia (Federated States of)", "Micronesia (Federated States of)"),
 ("Monaco", "Monaco"),
 ("Mongolia", "Mongolia"),
 ("Montenegro", "Montenegro"),
 ("Morocco", "Morocco"),
 ("Mozambique", "Mozambique"),
 ("Myanmar", "Myanmar"),
 ("Namibia", "Namibia"),
 ("Nauru", "Nauru"),
 ("Nepal", "Nepal"),
 ("Netherlands", "Netherlands"),
 ("New Zealand", "New Zealand"),
 ("Nicaragua", "Nicaragua"),
 ("Niger", "Niger"),
 ("Nigeria", "Nigeria"),
 ("Norway", "Norway"),
 ("Oman", "Oman"),
 ("Pakistan", "Pakistan"),
 ("Palau", "Palau"),
 ("Panama", "Panama"),
 ("Papua New Guinea", "Papua New Guinea"),
 ("Paraguay", "Paraguay"),
 ("Peru", "Peru"),
 ("Philippines", "Philippines"),
 ("Poland", "Poland"),
 ("Portugal", "Portugal"),
 ("Qatar", "Qatar"),
 ("Republic of Korea (South Korea)", "Republic of Korea (South Korea)"),
 ("Republic of Moldova", "Republic of Moldova"),
 ("Romania", "Romania"),
 ("Russian Federation", "Russian Federation"),
 ("Rwanda", "Rwanda"),
 ("Saint Kitts and Nevis", "Saint Kitts and Nevis"),
 ("Saint Lucia", "Saint Lucia"),
 ("Saint Vincent and the Grenadines", "Saint Vincent and the Grenadines"),
 ("Samoa", "Samoa"),
 ("San Marino", "San Marino"),
 ("Sao Tome and Principe", "Sao Tome and Principe"),
 ("Saudi Arabia", "Saudi Arabia"),
 ("Senegal", "Senegal"),
 ("Serbia", "Serbia"),
 ("Seychelles", "Seychelles"),
 ("Sierra Leone", "Sierra Leone"),
 ("Singapore", "Singapore"),
 ("Slovakia", "Slovakia"),
 ("Slovenia", "Slovenia"),
 ("Solomon Islands", "Solomon Islands"),
 ("Somalia", "Somalia"),
 ("South Africa", "South Africa"),
 ("South Sudan", "South Sudan"),
 ("Spain", "Spain"),
 ("Sri Lanka", "Sri Lanka"),
 ("Sudan", "Sudan"),
 ("Suriname", "Suriname"),
 ("Swaziland", "Swaziland"),
 ("Sweden", "Sweden"),
 ("Switzerland", "Switzerland"),
 ("Syrian Arab Republic", "Syrian Arab Republic"),
 ("Tajikistan", "Tajikistan"),
 ("Thailand", "Thailand"),
 ("Timor-Leste", "Timor-Leste"),
 ("Togo", "Togo"),
 ("Tonga", "Tonga"),
 ("Trinidad and Tobago", "Trinidad and Tobago"),
 ("Tunisia", "Tunisia"),
 ("Turkey", "Turkey"),
 ("Turkmenistan", "Turkmenistan"),
 ("Tuvalu", "Tuvalu"),
 ("Uganda", "Uganda"),
 ("Ukraine", "Ukraine"),
 ("United Arab Emirates", "United Arab Emirates"),
 ("United Kingdom of Great Britain and Northern Ireland", "United Kingdom of Great Britain and Northern Ireland"),
 ("United Republic of Tanzania", "United Republic of Tanzania"),
 ("United States of America", "United States of America"),
 ("Uruguay", "Uruguay"),
 ("Uzbekistan", "Uzbekistan"),
 ("Vanuatu", "Vanuatu"),
 ("Venezuela", "Venezuela"),
 ("Vietnam", "Vietnam"),
 ("Yemen", "Yemen"),
 ("Zambia", "Zambia"),
 ("Zimbabwe", "Zimbabwe"),
]

PROFILE_TZs = [
 ("Africa/Abidjan", "Africa/Abidjan"),
 ("Africa/Accra", "Africa/Accra"),
 ("Africa/Addis_Ababa", "Africa/Addis_Ababa"),
 ("Africa/Algiers", "Africa/Algiers"),
 ("Africa/Asmara", "Africa/Asmara"),
 ("Africa/Asmera", "Africa/Asmera"),
 ("Africa/Bamako", "Africa/Bamako"),
 ("Africa/Bangui", "Africa/Bangui"),
 ("Africa/Banjul", "Africa/Banjul"),
 ("Africa/Bissau", "Africa/Bissau"),
 ("Africa/Blantyre", "Africa/Blantyre"),
 ("Africa/Brazzaville", "Africa/Brazzaville"),
 ("Africa/Bujumbura", "Africa/Bujumbura"),
 ("Africa/Cairo", "Africa/Cairo"),
 ("Africa/Casablanca", "Africa/Casablanca"),
 ("Africa/Ceuta", "Africa/Ceuta"),
 ("Africa/Conakry", "Africa/Conakry"),
 ("Africa/Dakar", "Africa/Dakar"),
 ("Africa/Dar_es_Salaam", "Africa/Dar_es_Salaam"),
 ("Africa/Djibouti", "Africa/Djibouti"),
 ("Africa/Douala", "Africa/Douala"),
 ("Africa/El_Aaiun", "Africa/El_Aaiun"),
 ("Africa/Freetown", "Africa/Freetown"),
 ("Africa/Gaborone", "Africa/Gaborone"),
 ("Africa/Harare", "Africa/Harare"),
 ("Africa/Johannesburg", "Africa/Johannesburg"),
 ("Africa/Juba", "Africa/Juba"),
 ("Africa/Kampala", "Africa/Kampala"),
 ("Africa/Khartoum", "Africa/Khartoum"),
 ("Africa/Kigali", "Africa/Kigali"),
 ("Africa/Kinshasa", "Africa/Kinshasa"),
 ("Africa/Lagos", "Africa/Lagos"),
 ("Africa/Libreville", "Africa/Libreville"),
 ("Africa/Lome", "Africa/Lome"),
 ("Africa/Luanda", "Africa/Luanda"),
 ("Africa/Lubumbashi", "Africa/Lubumbashi"),
 ("Africa/Lusaka", "Africa/Lusaka"),
 ("Africa/Malabo", "Africa/Malabo"),
 ("Africa/Maputo", "Africa/Maputo"),
 ("Africa/Maseru", "Africa/Maseru"),
 ("Africa/Mbabane", "Africa/Mbabane"),
 ("Africa/Mogadishu", "Africa/Mogadishu"),
 ("Africa/Monrovia", "Africa/Monrovia"),
 ("Africa/Nairobi", "Africa/Nairobi"),
 ("Africa/Ndjamena", "Africa/Ndjamena"),
 ("Africa/Niamey", "Africa/Niamey"),
 ("Africa/Nouakchott", "Africa/Nouakchott"),
 ("Africa/Ouagadougou", "Africa/Ouagadougou"),
 ("Africa/Porto-Novo", "Africa/Porto-Novo"),
 ("Africa/Sao_Tome", "Africa/Sao_Tome"),
 ("Africa/Timbuktu", "Africa/Timbuktu"),
 ("Africa/Tripoli", "Africa/Tripoli"),
 ("Africa/Tunis", "Africa/Tunis"),
 ("Africa/Windhoek", "Africa/Windhoek"),
 ("America/Adak", "America/Adak"),
 ("America/Anchorage", "America/Anchorage"),
 ("America/Anguilla", "America/Anguilla"),
 ("America/Antigua", "America/Antigua"),
 ("America/Araguaina", "America/Araguaina"),
 ("America/Argentina/Buenos_Aires", "America/Argentina/Buenos_Aires"),
 ("America/Argentina/Catamarca", "America/Argentina/Catamarca"),
 ("America/Argentina/ComodRivadavia", "America/Argentina/ComodRivadavia"),
 ("America/Argentina/Cordoba", "America/Argentina/Cordoba"),
 ("America/Argentina/Jujuy", "America/Argentina/Jujuy"),
 ("America/Argentina/La_Rioja", "America/Argentina/La_Rioja"),
 ("America/Argentina/Mendoza", "America/Argentina/Mendoza"),
 ("America/Argentina/Rio_Gallegos", "America/Argentina/Rio_Gallegos"),
 ("America/Argentina/Salta", "America/Argentina/Salta"),
 ("America/Argentina/San_Juan", "America/Argentina/San_Juan"),
 ("America/Argentina/San_Luis", "America/Argentina/San_Luis"),
 ("America/Argentina/Tucuman", "America/Argentina/Tucuman"),
 ("America/Argentina/Ushuaia", "America/Argentina/Ushuaia"),
 ("America/Aruba", "America/Aruba"),
 ("America/Asuncion", "America/Asuncion"),
 ("America/Atikokan", "America/Atikokan"),
 ("America/Atka", "America/Atka"),
 ("America/Bahia", "America/Bahia"),
 ("America/Bahia_Banderas", "America/Bahia_Banderas"),
 ("America/Barbados", "America/Barbados"),
 ("America/Belem", "America/Belem"),
 ("America/Belize", "America/Belize"),
 ("America/Blanc-Sablon", "America/Blanc-Sablon"),
 ("America/Boa_Vista", "America/Boa_Vista"),
 ("America/Bogota", "America/Bogota"),
 ("America/Boise", "America/Boise"),
 ("America/Buenos_Aires", "America/Buenos_Aires"),
 ("America/Cambridge_Bay", "America/Cambridge_Bay"),
 ("America/Campo_Grande", "America/Campo_Grande"),
 ("America/Cancun", "America/Cancun"),
 ("America/Caracas", "America/Caracas"),
 ("America/Catamarca", "America/Catamarca"),
 ("America/Cayenne", "America/Cayenne"),
 ("America/Cayman", "America/Cayman"),
 ("America/Chicago", "America/Chicago"),
 ("America/Chihuahua", "America/Chihuahua"),
 ("America/Coral_Harbour", "America/Coral_Harbour"),
 ("America/Cordoba", "America/Cordoba"),
 ("America/Costa_Rica", "America/Costa_Rica"),
 ("America/Creston", "America/Creston"),
 ("America/Cuiaba", "America/Cuiaba"),
 ("America/Curacao", "America/Curacao"),
 ("America/Danmarkshavn", "America/Danmarkshavn"),
 ("America/Dawson", "America/Dawson"),
 ("America/Dawson_Creek", "America/Dawson_Creek"),
 ("America/Denver", "America/Denver"),
 ("America/Detroit", "America/Detroit"),
 ("America/Dominica", "America/Dominica"),
 ("America/Edmonton", "America/Edmonton"),
 ("America/Eirunepe", "America/Eirunepe"),
 ("America/El_Salvador", "America/El_Salvador"),
 ("America/Ensenada", "America/Ensenada"),
 ("America/Fort_Wayne", "America/Fort_Wayne"),
 ("America/Fortaleza", "America/Fortaleza"),
 ("America/Glace_Bay", "America/Glace_Bay"),
 ("America/Godthab", "America/Godthab"),
 ("America/Goose_Bay", "America/Goose_Bay"),
 ("America/Grand_Turk", "America/Grand_Turk"),
 ("America/Grenada", "America/Grenada"),
 ("America/Guadeloupe", "America/Guadeloupe"),
 ("America/Guatemala", "America/Guatemala"),
 ("America/Guayaquil", "America/Guayaquil"),
 ("America/Guyana", "America/Guyana"),
 ("America/Halifax", "America/Halifax"),
 ("America/Havana", "America/Havana"),
 ("America/Hermosillo", "America/Hermosillo"),
 ("America/Indiana/Indianapolis", "America/Indiana/Indianapolis"),
 ("America/Indiana/Knox", "America/Indiana/Knox"),
 ("America/Indiana/Marengo", "America/Indiana/Marengo"),
 ("America/Indiana/Petersburg", "America/Indiana/Petersburg"),
 ("America/Indiana/Tell_City", "America/Indiana/Tell_City"),
 ("America/Indiana/Vevay", "America/Indiana/Vevay"),
 ("America/Indiana/Vincennes", "America/Indiana/Vincennes"),
 ("America/Indiana/Winamac", "America/Indiana/Winamac"),
 ("America/Indianapolis", "America/Indianapolis"),
 ("America/Inuvik", "America/Inuvik"),
 ("America/Iqaluit", "America/Iqaluit"),
 ("America/Jamaica", "America/Jamaica"),
 ("America/Jujuy", "America/Jujuy"),
 ("America/Juneau", "America/Juneau"),
 ("America/Kentucky/Louisville", "America/Kentucky/Louisville"),
 ("America/Kentucky/Monticello", "America/Kentucky/Monticello"),
 ("America/Knox_IN", "America/Knox_IN"),
 ("America/Kralendijk", "America/Kralendijk"),
 ("America/La_Paz", "America/La_Paz"),
 ("America/Lima", "America/Lima"),
 ("America/Los_Angeles", "America/Los_Angeles"),
 ("America/Louisville", "America/Louisville"),
 ("America/Lower_Princes", "America/Lower_Princes"),
 ("America/Maceio", "America/Maceio"),
 ("America/Managua", "America/Managua"),
 ("America/Manaus", "America/Manaus"),
 ("America/Marigot", "America/Marigot"),
 ("America/Martinique", "America/Martinique"),
 ("America/Matamoros", "America/Matamoros"),
 ("America/Mazatlan", "America/Mazatlan"),
 ("America/Mendoza", "America/Mendoza"),
 ("America/Menominee", "America/Menominee"),
 ("America/Merida", "America/Merida"),
 ("America/Metlakatla", "America/Metlakatla"),
 ("America/Mexico_City", "America/Mexico_City"),
 ("America/Miquelon", "America/Miquelon"),
 ("America/Moncton", "America/Moncton"),
 ("America/Monterrey", "America/Monterrey"),
 ("America/Montevideo", "America/Montevideo"),
 ("America/Montreal", "America/Montreal"),
 ("America/Montserrat", "America/Montserrat"),
 ("America/Nassau", "America/Nassau"),
 ("America/New_York", "America/New_York"),
 ("America/Nipigon", "America/Nipigon"),
 ("America/Nome", "America/Nome"),
 ("America/Noronha", "America/Noronha"),
 ("America/North_Dakota/Beulah", "America/North_Dakota/Beulah"),
 ("America/North_Dakota/Center", "America/North_Dakota/Center"),
 ("America/North_Dakota/New_Salem", "America/North_Dakota/New_Salem"),
 ("America/Ojinaga", "America/Ojinaga"),
 ("America/Panama", "America/Panama"),
 ("America/Pangnirtung", "America/Pangnirtung"),
 ("America/Paramaribo", "America/Paramaribo"),
 ("America/Phoenix", "America/Phoenix"),
 ("America/Port-au-Prince", "America/Port-au-Prince"),
 ("America/Port_of_Spain", "America/Port_of_Spain"),
 ("America/Porto_Acre", "America/Porto_Acre"),
 ("America/Porto_Velho", "America/Porto_Velho"),
 ("America/Puerto_Rico", "America/Puerto_Rico"),
 ("America/Rainy_River", "America/Rainy_River"),
 ("America/Rankin_Inlet", "America/Rankin_Inlet"),
 ("America/Recife", "America/Recife"),
 ("America/Resolute", "America/Resolute"),
 ("America/Rio_Branco", "America/Rio_Branco"),
 ("America/Rosario", "America/Rosario"),
 ("America/Santa_Isabel", "America/Santa_Isabel"),
 ("America/Santarem", "America/Santarem"),
 ("America/Santiago", "America/Santiago"),
 ("America/Santo_Domingo", "America/Santo_Domingo"),
 ("America/Sao_Paulo", "America/Sao_Paulo"),
 ("America/Scoresbysund", "America/Scoresbysund"),
 ("America/Shiprock", "America/Shiprock"),
 ("America/Sitka", "America/Sitka"),
 ("America/St_Barthelemy", "America/St_Barthelemy"),
 ("America/St_Johns", "America/St_Johns"),
 ("America/St_Kitts", "America/St_Kitts"),
 ("America/St_Lucia", "America/St_Lucia"),
 ("America/St_Thomas", "America/St_Thomas"),
 ("America/St_Vincent", "America/St_Vincent"),
 ("America/Swift_Current", "America/Swift_Current"),
 ("America/Tegucigalpa", "America/Tegucigalpa"),
 ("America/Thule", "America/Thule"),
 ("America/Thunder_Bay", "America/Thunder_Bay"),
 ("America/Tijuana", "America/Tijuana"),
 ("America/Toronto", "America/Toronto"),
 ("America/Tortola", "America/Tortola"),
 ("America/Vancouver", "America/Vancouver"),
 ("America/Virgin", "America/Virgin"),
 ("America/Whitehorse", "America/Whitehorse"),
 ("America/Winnipeg", "America/Winnipeg"),
 ("America/Yakutat", "America/Yakutat"),
 ("America/Yellowknife", "America/Yellowknife"),
 ("Antarctica/Casey", "Antarctica/Casey"),
 ("Antarctica/Davis", "Antarctica/Davis"),
 ("Antarctica/DumontDUrville", "Antarctica/DumontDUrville"),
 ("Antarctica/Macquarie", "Antarctica/Macquarie"),
 ("Antarctica/Mawson", "Antarctica/Mawson"),
 ("Antarctica/McMurdo", "Antarctica/McMurdo"),
 ("Antarctica/Palmer", "Antarctica/Palmer"),
 ("Antarctica/Rothera", "Antarctica/Rothera"),
 ("Antarctica/South_Pole", "Antarctica/South_Pole"),
 ("Antarctica/Syowa", "Antarctica/Syowa"),
 ("Antarctica/Troll", "Antarctica/Troll"),
 ("Antarctica/Vostok", "Antarctica/Vostok"),
 ("Arctic/Longyearbyen", "Arctic/Longyearbyen"),
 ("Asia/Aden", "Asia/Aden"),
 ("Asia/Almaty", "Asia/Almaty"),
 ("Asia/Amman", "Asia/Amman"),
 ("Asia/Anadyr", "Asia/Anadyr"),
 ("Asia/Aqtau", "Asia/Aqtau"),
 ("Asia/Aqtobe", "Asia/Aqtobe"),
 ("Asia/Ashgabat", "Asia/Ashgabat"),
 ("Asia/Ashkhabad", "Asia/Ashkhabad"),
 ("Asia/Baghdad", "Asia/Baghdad"),
 ("Asia/Bahrain", "Asia/Bahrain"),
 ("Asia/Baku", "Asia/Baku"),
 ("Asia/Bangkok", "Asia/Bangkok"),
 ("Asia/Beirut", "Asia/Beirut"),
 ("Asia/Bishkek", "Asia/Bishkek"),
 ("Asia/Brunei", "Asia/Brunei"),
 ("Asia/Calcutta", "Asia/Calcutta"),
 ("Asia/Chita", "Asia/Chita"),
 ("Asia/Choibalsan", "Asia/Choibalsan"),
 ("Asia/Chongqing", "Asia/Chongqing"),
 ("Asia/Chungking", "Asia/Chungking"),
 ("Asia/Colombo", "Asia/Colombo"),
 ("Asia/Dacca", "Asia/Dacca"),
 ("Asia/Damascus", "Asia/Damascus"),
 ("Asia/Dhaka", "Asia/Dhaka"),
 ("Asia/Dili", "Asia/Dili"),
 ("Asia/Dubai", "Asia/Dubai"),
 ("Asia/Dushanbe", "Asia/Dushanbe"),
 ("Asia/Gaza", "Asia/Gaza"),
 ("Asia/Harbin", "Asia/Harbin"),
 ("Asia/Hebron", "Asia/Hebron"),
 ("Asia/Ho_Chi_Minh", "Asia/Ho_Chi_Minh"),
 ("Asia/Hong_Kong", "Asia/Hong_Kong"),
 ("Asia/Hovd", "Asia/Hovd"),
 ("Asia/Irkutsk", "Asia/Irkutsk"),
 ("Asia/Istanbul", "Asia/Istanbul"),
 ("Asia/Jakarta", "Asia/Jakarta"),
 ("Asia/Jayapura", "Asia/Jayapura"),
 ("Asia/Jerusalem", "Asia/Jerusalem"),
 ("Asia/Kabul", "Asia/Kabul"),
 ("Asia/Kamchatka", "Asia/Kamchatka"),
 ("Asia/Karachi", "Asia/Karachi"),
 ("Asia/Kashgar", "Asia/Kashgar"),
 ("Asia/Kathmandu", "Asia/Kathmandu"),
 ("Asia/Katmandu", "Asia/Katmandu"),
 ("Asia/Khandyga", "Asia/Khandyga"),
 ("Asia/Kolkata", "Asia/Kolkata"),
 ("Asia/Krasnoyarsk", "Asia/Krasnoyarsk"),
 ("Asia/Kuala_Lumpur", "Asia/Kuala_Lumpur"),
 ("Asia/Kuching", "Asia/Kuching"),
 ("Asia/Kuwait", "Asia/Kuwait"),
 ("Asia/Macao", "Asia/Macao"),
 ("Asia/Macau", "Asia/Macau"),
 ("Asia/Magadan", "Asia/Magadan"),
 ("Asia/Makassar", "Asia/Makassar"),
 ("Asia/Manila", "Asia/Manila"),
 ("Asia/Muscat", "Asia/Muscat"),
 ("Asia/Nicosia", "Asia/Nicosia"),
 ("Asia/Novokuznetsk", "Asia/Novokuznetsk"),
 ("Asia/Novosibirsk", "Asia/Novosibirsk"),
 ("Asia/Omsk", "Asia/Omsk"),
 ("Asia/Oral", "Asia/Oral"),
 ("Asia/Phnom_Penh", "Asia/Phnom_Penh"),
 ("Asia/Pontianak", "Asia/Pontianak"),
 ("Asia/Pyongyang", "Asia/Pyongyang"),
 ("Asia/Qatar", "Asia/Qatar"),
 ("Asia/Qyzylorda", "Asia/Qyzylorda"),
 ("Asia/Rangoon", "Asia/Rangoon"),
 ("Asia/Riyadh", "Asia/Riyadh"),
 ("Asia/Saigon", "Asia/Saigon"),
 ("Asia/Sakhalin", "Asia/Sakhalin"),
 ("Asia/Samarkand", "Asia/Samarkand"),
 ("Asia/Seoul", "Asia/Seoul"),
 ("Asia/Shanghai", "Asia/Shanghai"),
 ("Asia/Singapore", "Asia/Singapore"),
 ("Asia/Srednekolymsk", "Asia/Srednekolymsk"),
 ("Asia/Taipei", "Asia/Taipei"),
 ("Asia/Tashkent", "Asia/Tashkent"),
 ("Asia/Tbilisi", "Asia/Tbilisi"),
 ("Asia/Tehran", "Asia/Tehran"),
 ("Asia/Tel_Aviv", "Asia/Tel_Aviv"),
 ("Asia/Thimbu", "Asia/Thimbu"),
 ("Asia/Thimphu", "Asia/Thimphu"),
 ("Asia/Tokyo", "Asia/Tokyo"),
 ("Asia/Ujung_Pandang", "Asia/Ujung_Pandang"),
 ("Asia/Ulaanbaatar", "Asia/Ulaanbaatar"),
 ("Asia/Ulan_Bator", "Asia/Ulan_Bator"),
 ("Asia/Urumqi", "Asia/Urumqi"),
 ("Asia/Ust-Nera", "Asia/Ust-Nera"),
 ("Asia/Vientiane", "Asia/Vientiane"),
 ("Asia/Vladivostok", "Asia/Vladivostok"),
 ("Asia/Yakutsk", "Asia/Yakutsk"),
 ("Asia/Yekaterinburg", "Asia/Yekaterinburg"),
 ("Asia/Yerevan", "Asia/Yerevan"),
 ("Atlantic/Azores", "Atlantic/Azores"),
 ("Atlantic/Bermuda", "Atlantic/Bermuda"),
 ("Atlantic/Canary", "Atlantic/Canary"),
 ("Atlantic/Cape_Verde", "Atlantic/Cape_Verde"),
 ("Atlantic/Faeroe", "Atlantic/Faeroe"),
 ("Atlantic/Faroe", "Atlantic/Faroe"),
 ("Atlantic/Jan_Mayen", "Atlantic/Jan_Mayen"),
 ("Atlantic/Madeira", "Atlantic/Madeira"),
 ("Atlantic/Reykjavik", "Atlantic/Reykjavik"),
 ("Atlantic/South_Georgia", "Atlantic/South_Georgia"),
 ("Atlantic/St_Helena", "Atlantic/St_Helena"),
 ("Atlantic/Stanley", "Atlantic/Stanley"),
 ("Australia/ACT", "Australia/ACT"),
 ("Australia/Adelaide", "Australia/Adelaide"),
 ("Australia/Brisbane", "Australia/Brisbane"),
 ("Australia/Broken_Hill", "Australia/Broken_Hill"),
 ("Australia/Canberra", "Australia/Canberra"),
 ("Australia/Currie", "Australia/Currie"),
 ("Australia/Darwin", "Australia/Darwin"),
 ("Australia/Eucla", "Australia/Eucla"),
 ("Australia/Hobart", "Australia/Hobart"),
 ("Australia/LHI", "Australia/LHI"),
 ("Australia/Lindeman", "Australia/Lindeman"),
 ("Australia/Lord_Howe", "Australia/Lord_Howe"),
 ("Australia/Melbourne", "Australia/Melbourne"),
 ("Australia/NSW", "Australia/NSW"),
 ("Australia/North", "Australia/North"),
 ("Australia/Perth", "Australia/Perth"),
 ("Australia/Queensland", "Australia/Queensland"),
 ("Australia/South", "Australia/South"),
 ("Australia/Sydney", "Australia/Sydney"),
 ("Australia/Tasmania", "Australia/Tasmania"),
 ("Australia/Victoria", "Australia/Victoria"),
 ("Australia/West", "Australia/West"),
 ("Australia/Yancowinna", "Australia/Yancowinna"),
 ("Brazil/Acre", "Brazil/Acre"),
 ("Brazil/DeNoronha", "Brazil/DeNoronha"),
 ("Brazil/East", "Brazil/East"),
 ("Brazil/West", "Brazil/West"),
 ("Canada/Atlantic", "Canada/Atlantic"),
 ("Canada/Central", "Canada/Central"),
 ("Canada/Eastern", "Canada/Eastern"),
 ("Canada/Mountain", "Canada/Mountain"),
 ("Canada/Newfoundland", "Canada/Newfoundland"),
 ("Canada/Pacific", "Canada/Pacific"),
 ("Canada/Saskatchewan", "Canada/Saskatchewan"),
 ("Canada/Yukon", "Canada/Yukon"),
 ("Chile/Continental", "Chile/Continental"),
 ("Chile/EasterIsland", "Chile/EasterIsland"),
 ("Etc/GMT", "Etc/GMT"),
 ("Etc/Greenwich", "Etc/Greenwich"),
 ("Etc/UCT", "Etc/UCT"),
 ("Etc/UTC", "Etc/UTC"),
 ("Etc/Universal", "Etc/Universal"),
 ("Etc/Zulu", "Etc/Zulu"),
 ("Europe/Amsterdam", "Europe/Amsterdam"),
 ("Europe/Andorra", "Europe/Andorra"),
 ("Europe/Athens", "Europe/Athens"),
 ("Europe/Belfast", "Europe/Belfast"),
 ("Europe/Belgrade", "Europe/Belgrade"),
 ("Europe/Berlin", "Europe/Berlin"),
 ("Europe/Bratislava", "Europe/Bratislava"),
 ("Europe/Brussels", "Europe/Brussels"),
 ("Europe/Bucharest", "Europe/Bucharest"),
 ("Europe/Budapest", "Europe/Budapest"),
 ("Europe/Busingen", "Europe/Busingen"),
 ("Europe/Chisinau", "Europe/Chisinau"),
 ("Europe/Copenhagen", "Europe/Copenhagen"),
 ("Europe/Dublin", "Europe/Dublin"),
 ("Europe/Gibraltar", "Europe/Gibraltar"),
 ("Europe/Guernsey", "Europe/Guernsey"),
 ("Europe/Helsinki", "Europe/Helsinki"),
 ("Europe/Isle_of_Man", "Europe/Isle_of_Man"),
 ("Europe/Istanbul", "Europe/Istanbul"),
 ("Europe/Jersey", "Europe/Jersey"),
 ("Europe/Kaliningrad", "Europe/Kaliningrad"),
 ("Europe/Kiev", "Europe/Kiev"),
 ("Europe/Lisbon", "Europe/Lisbon"),
 ("Europe/Ljubljana", "Europe/Ljubljana"),
 ("Europe/London", "Europe/London"),
 ("Europe/Luxembourg", "Europe/Luxembourg"),
 ("Europe/Madrid", "Europe/Madrid"),
 ("Europe/Malta", "Europe/Malta"),
 ("Europe/Mariehamn", "Europe/Mariehamn"),
 ("Europe/Minsk", "Europe/Minsk"),
 ("Europe/Monaco", "Europe/Monaco"),
 ("Europe/Moscow", "Europe/Moscow"),
 ("Europe/Nicosia", "Europe/Nicosia"),
 ("Europe/Oslo", "Europe/Oslo"),
 ("Europe/Paris", "Europe/Paris"),
 ("Europe/Podgorica", "Europe/Podgorica"),
 ("Europe/Prague", "Europe/Prague"),
 ("Europe/Riga", "Europe/Riga"),
 ("Europe/Rome", "Europe/Rome"),
 ("Europe/Samara", "Europe/Samara"),
 ("Europe/San_Marino", "Europe/San_Marino"),
 ("Europe/Sarajevo", "Europe/Sarajevo"),
 ("Europe/Simferopol", "Europe/Simferopol"),
 ("Europe/Skopje", "Europe/Skopje"),
 ("Europe/Sofia", "Europe/Sofia"),
 ("Europe/Stockholm", "Europe/Stockholm"),
 ("Europe/Tallinn", "Europe/Tallinn"),
 ("Europe/Tirane", "Europe/Tirane"),
 ("Europe/Tiraspol", "Europe/Tiraspol"),
 ("Europe/Uzhgorod", "Europe/Uzhgorod"),
 ("Europe/Vaduz", "Europe/Vaduz"),
 ("Europe/Vatican", "Europe/Vatican"),
 ("Europe/Vienna", "Europe/Vienna"),
 ("Europe/Vilnius", "Europe/Vilnius"),
 ("Europe/Volgograd", "Europe/Volgograd"),
 ("Europe/Warsaw", "Europe/Warsaw"),
 ("Europe/Zagreb", "Europe/Zagreb"),
 ("Europe/Zaporozhye", "Europe/Zaporozhye"),
 ("Europe/Zurich", "Europe/Zurich"),
 ("GB", "GB"),
 ("Indian/Antananarivo", "Indian/Antananarivo"),
 ("Indian/Chagos", "Indian/Chagos"),
 ("Indian/Christmas", "Indian/Christmas"),
 ("Indian/Cocos", "Indian/Cocos"),
 ("Indian/Comoro", "Indian/Comoro"),
 ("Indian/Kerguelen", "Indian/Kerguelen"),
 ("Indian/Mahe", "Indian/Mahe"),
 ("Indian/Maldives", "Indian/Maldives"),
 ("Indian/Mauritius", "Indian/Mauritius"),
 ("Indian/Mayotte", "Indian/Mayotte"),
 ("Indian/Reunion", "Indian/Reunion"),
 ("Mexico/BajaNorte", "Mexico/BajaNorte"),
 ("Mexico/BajaSur", "Mexico/BajaSur"),
 ("Mexico/General", "Mexico/General"),
 ("NZ", "NZ"),
 ("PRC", "PRC"),
 ("Pacific/Apia", "Pacific/Apia"),
 ("Pacific/Auckland", "Pacific/Auckland"),
 ("Pacific/Bougainville", "Pacific/Bougainville"),
 ("Pacific/Chatham", "Pacific/Chatham"),
 ("Pacific/Chuuk", "Pacific/Chuuk"),
 ("Pacific/Easter", "Pacific/Easter"),
 ("Pacific/Efate", "Pacific/Efate"),
 ("Pacific/Enderbury", "Pacific/Enderbury"),
 ("Pacific/Fakaofo", "Pacific/Fakaofo"),
 ("Pacific/Fiji", "Pacific/Fiji"),
 ("Pacific/Funafuti", "Pacific/Funafuti"),
 ("Pacific/Galapagos", "Pacific/Galapagos"),
 ("Pacific/Gambier", "Pacific/Gambier"),
 ("Pacific/Guadalcanal", "Pacific/Guadalcanal"),
 ("Pacific/Guam", "Pacific/Guam"),
 ("Pacific/Honolulu", "Pacific/Honolulu"),
 ("Pacific/Johnston", "Pacific/Johnston"),
 ("Pacific/Kiritimati", "Pacific/Kiritimati"),
 ("Pacific/Kosrae", "Pacific/Kosrae"),
 ("Pacific/Kwajalein", "Pacific/Kwajalein"),
 ("Pacific/Majuro", "Pacific/Majuro"),
 ("Pacific/Marquesas", "Pacific/Marquesas"),
 ("Pacific/Midway", "Pacific/Midway"),
 ("Pacific/Nauru", "Pacific/Nauru"),
 ("Pacific/Niue", "Pacific/Niue"),
 ("Pacific/Norfolk", "Pacific/Norfolk"),
 ("Pacific/Noumea", "Pacific/Noumea"),
 ("Pacific/Pago_Pago", "Pacific/Pago_Pago"),
 ("Pacific/Palau", "Pacific/Palau"),
 ("Pacific/Pitcairn", "Pacific/Pitcairn"),
 ("Pacific/Pohnpei", "Pacific/Pohnpei"),
 ("Pacific/Ponape", "Pacific/Ponape"),
 ("Pacific/Port_Moresby", "Pacific/Port_Moresby"),
 ("Pacific/Rarotonga", "Pacific/Rarotonga"),
 ("Pacific/Saipan", "Pacific/Saipan"),
 ("Pacific/Samoa", "Pacific/Samoa"),
 ("Pacific/Tahiti", "Pacific/Tahiti"),
 ("Pacific/Tarawa", "Pacific/Tarawa"),
 ("Pacific/Tongatapu", "Pacific/Tongatapu"),
 ("Pacific/Truk", "Pacific/Truk"),
 ("Pacific/Wake", "Pacific/Wake"),
 ("Pacific/Wallis", "Pacific/Wallis"),
 ("Pacific/Yap", "Pacific/Yap"),
 ("ROC", "ROC"),
 ("ROK", "ROK"),
 ("UTC", "UTC"),
]

PROFILE_GENDERs = [
 ("M", "Male"),
 ("F", "Female"),
]

def _getGames():
    ''' Retrieves stored games and populates within a selectfield '''
    games = db.Games.find()
    size = games.count() - 1
    choices = []

    if len(choices) == 0:
        return [('none', 'None')]

    while size >= 0:
        choices.append((games[size]['game_id'], games[size]['title']))
        size -= 1
    return choices

def _getCategories():
    ''' Retrieves stored Categories and populates within a selectfield '''
    cat = Category()
    cats = cat.getCategories()
    choices = []
    if len(cats) == 0:
        return [('none', 'None')]

    for key in cats:
        choices.append((cats[key]['title'], cats[key]['title']))
        
    return choices

class ThreadForm(FlaskForm):
    title = StringField('Title', validators=[DataRequired()])
    cat = SelectField('Pick a Category', choices=_getCategories())
    description = TextAreaField()
    hashtag = StringField('Hashtag', validators=[DataRequired()])
    image = FileField()

class LoginForm(FlaskForm):
    ''' Login Form '''
    username = StringField('Username', validators=[DataRequired()])
    pw = PasswordField('Password', validators=[DataRequired()])
    submit = SubmitField('Sign In')

class RegisterForm(FlaskForm):
    ''' Registers new users with the app '''
    # name = StringField('Name', validators=[DataRequired()])
    username = StringField('Username', validators=[DataRequired()])
    firstname = StringField('First Name', validators=[DataRequired()])
    lastname = StringField('Last Name', validators=[DataRequired()])
    email = StringField('Email Address', validators=[DataRequired(), Email()])
    pw = PasswordField('Password', validators=[DataRequired()])
    pw2 = PasswordField('Repeat Password', validators=[DataRequired(), EqualTo('pw')])
    state = SelectField('State/Province', choices=PROFILE_STATEs)
    zip = StringField('ZIP/Postal Code', validators=[DataRequired()])
    city = StringField('City/Town', validators=[DataRequired()])
    country = SelectField('Country', choices=PROFILE_COUNTRYs)
    gender = SelectField('Gender', choices=PROFILE_GENDERs)
    timezone = SelectField('Time Zone', choices=PROFILE_TZs)
    # games = SelectField('Games', choices=_getGames())
    # games = SelectField('Games', choices=[('cod','cod'),('lol','lol'),('dota','dota')])
    submit = SubmitField('Register')

    def validate_username(self, name):
        ''' validates if a user exists '''
        user = db.Users.find_one({'id':name.data})
        if user is not None:
            raise ValidationError('Please use a different username.')

    def validate_email(self, email):
        ''' validates if a email exists '''
        email = db.Users.find_one({'id':email.data})
        if email is not None:
            raise ValidationError('Email is already in use.')

class ProfileForm(FlaskForm):
    ''' Edit Profile '''
    firstname = StringField('First Name', validators=[DataRequired()])
    lastname = StringField('Last Name', validators=[DataRequired()])
    email = StringField('Email Address', validators=[DataRequired(), Email()])
    username = StringField('Username', validators=[DataRequired()])
    state = SelectField('State/Province', choices=PROFILE_STATEs)
    zip = StringField('ZIP/Postal Code', validators=[DataRequired()])
    city = StringField('City/Town', validators=[DataRequired()])
    country = SelectField('Country', choices=PROFILE_COUNTRYs)
    gender = SelectField('Gender', choices=PROFILE_GENDERs)
    timezone = SelectField('Time Zone', choices=PROFILE_TZs)
    about_me = TextAreaField('About me', validators=[Length(min=0, max=240)])

    submit = SubmitField('Save Changes')

class CreateTournamentForm(FlaskForm):
    ''' Create new tournaments '''
    tournament_name = StringField('Tournament Name', validators=[DataRequired()])
    reg_start_date = DateField('Registration Start Date', format='%m/%d/%y', validators=[DataRequired()])
    reg_end_date = DateField('Registration End Date', format='%m/%d/%y', validators=[DataRequired()])
    tournament_start_date = DateTimeField('Tournament Start Date', format='%m/%d/%y', validators=[DataRequired()])

    submit = SubmitField('Create Tournament')

class BracketGeneratorForm(FlaskForm):
    tournament_name = StringField('Tournament Name')
    tournament_type = SelectField('Tournament Type',
                    choices=[('single elimination', 'Single Elimination'),
                    ('double elimination', 'Double Elimination'), ('round robin', 'Round Robin')
                    ])
    hold_third_place_match = BooleanField('Include a match for 3rd place between semifinal losers')
    rr_iteration = SelectField('Participants play each other', choices=[('1','Once'),('2','Twice'),('3','3 Times')])
    bracket_size = SelectField('Bracket Size',
                    choices=[('names','Use number of participants provided below'),
                        ('size','Select the size for a blank bracket')
                    ])
    number_of_participants = IntegerField('Number of Participants', validators=[Optional()])
    participants_team = TextAreaField('Participants / Teams')
    submit = SubmitField('GENERATE IT!')

    def validate(self):
        if not FlaskForm.validate(self):
            return False

        bracket_size = self.bracket_size.data
        if bracket_size == 'size':
            number_of_participants = self.number_of_participants.data
            if not number_of_participants:
                flash("Please provide at least 2 participants.")
                return False
        else:
            participants_team = self.participants_team.data
            if not participants_team.strip():
                flash("Please provide at least 2 participants.")
                return False
            participants_team = participants_team.strip().split('\r\n')
            if len(participants_team) < 2:
                flash("Please provide at least 2 participants.")
                return False
        return True

class TournamentRegistrationForm(FlaskForm):
    player_nickname = StringField('Player nickname', validators=[DataRequired()])
    player_email = StringField('Player email', validators=[DataRequired(), Email()])
    tournament = HiddenField(validators=[DataRequired()])
    i_agree = BooleanField()
    submit = SubmitField('Submit your registration')

    def validate(self):
        if not FlaskForm.validate(self):
            return False
        if self.i_agree.data == False:
            flash('There is invalid data in the form. Please check it and submit again.', category="error")
            return False
        return True


class SponsorshipForm(FlaskForm):
    """
    Sponsorship form for sponsors
    """
    name = StringField('Full Name', validators=[DataRequired()])
    email = StringField('Email', validators=[DataRequired(), Email()])
    gender = SelectField('Gender', choices=PROFILE_GENDERs)
    card_number = StringField('Credit Card Number', validators=[DataRequired()])
    card_expiry_month = StringField('Expiry Month', validators=[DataRequired()])
    card_expiry_year = StringField('Expiry Year', validators=[DataRequired()])
    card_cvv = StringField('CVV', validators=[DataRequired()])
    message = TextAreaField('Optional Message', validators=[])
    billing_address = StringField('Billing Address', validators=[DataRequired()])
    zip = StringField('ZIP/Postal Code', validators=[DataRequired()])
    city = StringField('City/Town', validators=[DataRequired()])
    state = SelectField('State/Province', choices=PROFILE_STATEs)
    country = SelectField('Country', choices=PROFILE_COUNTRYs)
    amount = IntegerField('Amount to Donate', validators=[DataRequired()])
    anonymous = BooleanField('Contribute Anonymously', validators=[])
    every_month = BooleanField('Contribute Monthly', validators=[])
    submit = SubmitField('Make Donation')
