From 23e04edafd0d49fcf94a7a1e78eed2f7d484e49b Mon Sep 17 00:00:00 2001 From: binaryatrocity Date: Tue, 25 Mar 2014 19:40:36 -0500 Subject: [PATCH] Fixed MutableDict. Redesigned profile,random,settings. Added user bios --- .gitignore | 2 +- __init__.py | 2 +- forms.py | 7 + models.py | 99 ++- static/country_codes.xml | 1250 ++++++++++++++++++++++++++++++++++++ static/css/app.css | 38 +- static/css/heropedia.css | 2 +- static/css/ts3_viewer.css | 5 +- teamspeak.py | 9 +- templates/hero_random.html | 87 +++ templates/index.html | 213 +++--- templates/layout.html | 37 +- templates/profile.html | 41 +- templates/settings.html | 41 ++ templates/sidenav.html | 12 +- templates/teamspeak.html | 2 +- utils.py | 69 +- views.py | 99 ++- 18 files changed, 1757 insertions(+), 258 deletions(-) create mode 100644 forms.py create mode 100644 static/country_codes.xml create mode 100644 templates/hero_random.html create mode 100644 templates/settings.html diff --git a/.gitignore b/.gitignore index ef3dbe7..68fbbcb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ __pycache__/ *.py[cod] *.so - +static/img/hero-images/*.png diff --git a/__init__.py b/__init__.py index 8d21f33..f7a4ffe 100644 --- a/__init__.py +++ b/__init__.py @@ -227,4 +227,4 @@ def utility_processor(): country_abbreviation_mapping=country_abbreviation_mapping) - ''' \ No newline at end of file + ''' diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..7caaf92 --- /dev/null +++ b/forms.py @@ -0,0 +1,7 @@ +from flask.ext.wtf import Form +from wtforms import TextField, BooleanField, TextAreaField + +class SettingsForm(Form): + public = BooleanField('public', default=True) + twitch = TextField('twitch') + bio_text = TextAreaField('bio_text') diff --git a/models.py b/models.py index 4882205..c657dfb 100644 --- a/models.py +++ b/models.py @@ -1,35 +1,110 @@ import simplejson as json +from random import choice from flask.ext.sqlalchemy import SQLAlchemy +from sqlalchemy.ext.mutable import Mutable from time import time from app import db +from utils import parse_valve_heropedia, complete_hero_data # Get a little of that Mongoness back class Json(db.TypeDecorator): - impl = db.Unicode + impl = db.Text + + def process_bind_param(self, value, dialect): + if value is not None: + value = json.dumps(value) + return value + + def process_result_value(self, value, dialect): + if value is not None: + value = json.loads(value) + return value + + +class MutableDict(Mutable, dict): + @classmethod + def coerce(cls, key, value): + if not isinstance(value, MutableDict): + if isinstance(value, dict): + return MutableDict(value) + return Mutable.coerce(key,value) + else: + return value + + def __delitem__(self, key): + dict.__delitem__(self, key) + self.changed() + + def __setitem__(self, key, value): + dict.__setitem__(self, key, value) + self.changed() + + def __getstate__(self): + return dict(self) + + def __setstate__(self, state): + self.update(self) - def process_bind_param(self, value, dialect): - return unicode(json.dumps(value)) - def process_result_value(self, value, dialect): - return json.loads(value) class User(db.Model): id = db.Column(db.Integer, primary_key=True) steam_id = db.Column(db.String(40), unique=True) nickname = db.Column(db.String(80)) avatar = db.Column(db.String(255)) + random_heroes = db.Column(MutableDict.as_mutable(Json)) + bio_text = db.Column(db.String(4096)) + last_seen = db.Column(db.DateTime) + twitch = db.Column(db.String(60)) @staticmethod def get_or_create(steam_id): - rv = User.query.filter_by(steam_id=steam_id).first() - if rv is None: - rv = User() - rv.steam_id = steam_id - db.session.add(rv) - return rv + rv = User.query.filter_by(steam_id=steam_id).first() + if rv is None: + rv = User() + rv.steam_id = steam_id + rv.random_heroes = {'current':None, 'completed':[]} + bio_text = '' + db.session.add(rv) + return rv + + @property + def random_hero(self): + if not self.random_heroes['current']: + heroes = [] + for (tavern_name, tavern) in parse_valve_heropedia(): + heroes.extend([complete_hero_data('name', entry['name']) for entry in tavern]) + if heroes: + self.random_heroes['current'] = choice(heroes) + self.random_heroes = self.random_heroes + db.session.commit() + return self.random_heroes['current'] + + @random_hero.setter + def random_hero(self, herodata): + self.random_heroes['current'] = herodata + self.random_heroes = self.random_heroes + db.session.commit() + + @property + def random_completed(self): + return self.random_heroes['completed'] + + def random_success(self): + self.random_heroes['completed'].append(self.random_heroes['current']['name']) + self.random_heroes['current'] = None + self.random_heroes = self.random_heroes + db.session.commit() + return self.random_hero + + def random_skip(self): + self.random_heroes['current'] = None + self.random_heroes = self.random_heroes + db.session.commit() + return self.random_hero def __repr__(self): - return ''.format(self.steam_id) + return ''.format(self.nickname) class TeamspeakData(db.Model): id = db.Column(db.Integer, primary_key=True) diff --git a/static/country_codes.xml b/static/country_codes.xml new file mode 100644 index 0000000..a30ba4b --- /dev/null +++ b/static/country_codes.xml @@ -0,0 +1,1250 @@ + + + + + AFGHANISTAN + AF + + + + ÅLAND ISLANDS + AX + + + + ALBANIA + AL + + + + ALGERIA + DZ + + + + AMERICAN SAMOA + AS + + + + ANDORRA + AD + + + + ANGOLA + AO + + + + ANGUILLA + AI + + + + ANTARCTICA + AQ + + + + ANTIGUA AND BARBUDA + AG + + + + ARGENTINA + AR + + + + ARMENIA + AM + + + + ARUBA + AW + + + + AUSTRALIA + AU + + + + AUSTRIA + AT + + + + AZERBAIJAN + AZ + + + + BAHAMAS + BS + + + + BAHRAIN + BH + + + + BANGLADESH + BD + + + + BARBADOS + BB + + + + BELARUS + BY + + + + BELGIUM + BE + + + + BELIZE + BZ + + + + BENIN + BJ + + + + BERMUDA + BM + + + + BHUTAN + BT + + + + BOLIVIA, PLURINATIONAL STATE OF + BO + + + + BONAIRE, SINT EUSTATIUS AND SABA + BQ + + + + BOSNIA AND HERZEGOVINA + BA + + + + BOTSWANA + BW + + + + BOUVET ISLAND + BV + + + + BRAZIL + BR + + + + BRITISH INDIAN OCEAN TERRITORY + IO + + + + BRUNEI DARUSSALAM + BN + + + + BULGARIA + BG + + + + BURKINA FASO + BF + + + + BURUNDI + BI + + + + CAMBODIA + KH + + + + CAMEROON + CM + + + + CANADA + CA + + + + CAPE VERDE + CV + + + + CAYMAN ISLANDS + KY + + + + CENTRAL AFRICAN REPUBLIC + CF + + + + CHAD + TD + + + + CHILE + CL + + + + CHINA + CN + + + + CHRISTMAS ISLAND + CX + + + + COCOS (KEELING) ISLANDS + CC + + + + COLOMBIA + CO + + + + COMOROS + KM + + + + CONGO + CG + + + + CONGO, THE DEMOCRATIC REPUBLIC OF THE + CD + + + + COOK ISLANDS + CK + + + + COSTA RICA + CR + + + + CÔTE D'IVOIRE + CI + + + + CROATIA + HR + + + + CUBA + CU + + + + CURAÇAO + CW + + + + CYPRUS + CY + + + + CZECH REPUBLIC + CZ + + + + DENMARK + DK + + + + DJIBOUTI + DJ + + + + DOMINICA + DM + + + + DOMINICAN REPUBLIC + DO + + + + ECUADOR + EC + + + + EGYPT + EG + + + + EL SALVADOR + SV + + + + EQUATORIAL GUINEA + GQ + + + + ERITREA + ER + + + + ESTONIA + EE + + + + ETHIOPIA + ET + + + + FALKLAND ISLANDS (MALVINAS) + FK + + + + FAROE ISLANDS + FO + + + + FIJI + FJ + + + + FINLAND + FI + + + + FRANCE + FR + + + + FRENCH GUIANA + GF + + + + FRENCH POLYNESIA + PF + + + + FRENCH SOUTHERN TERRITORIES + TF + + + + GABON + GA + + + + GAMBIA + GM + + + + GEORGIA + GE + + + + GERMANY + DE + + + + GHANA + GH + + + + GIBRALTAR + GI + + + + GREECE + GR + + + + GREENLAND + GL + + + + GRENADA + GD + + + + GUADELOUPE + GP + + + + GUAM + GU + + + + GUATEMALA + GT + + + + GUERNSEY + GG + + + + GUINEA + GN + + + + GUINEA-BISSAU + GW + + + + GUYANA + GY + + + + HAITI + HT + + + + HEARD ISLAND AND MCDONALD ISLANDS + HM + + + + HOLY SEE (VATICAN CITY STATE) + VA + + + + HONDURAS + HN + + + + HONG KONG + HK + + + + HUNGARY + HU + + + + ICELAND + IS + + + + INDIA + IN + + + + INDONESIA + ID + + + + IRAN, ISLAMIC REPUBLIC OF + IR + + + + IRAQ + IQ + + + + IRELAND + IE + + + + ISLE OF MAN + IM + + + + ISRAEL + IL + + + + ITALY + IT + + + + JAMAICA + JM + + + + JAPAN + JP + + + + JERSEY + JE + + + + JORDAN + JO + + + + KAZAKHSTAN + KZ + + + + KENYA + KE + + + + KIRIBATI + KI + + + + KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF + KP + + + + KOREA, REPUBLIC OF + KR + + + + KUWAIT + KW + + + + KYRGYZSTAN + KG + + + + LAO PEOPLE'S DEMOCRATIC REPUBLIC + LA + + + + LATVIA + LV + + + + LEBANON + LB + + + + LESOTHO + LS + + + + LIBERIA + LR + + + + LIBYA + LY + + + + LIECHTENSTEIN + LI + + + + LITHUANIA + LT + + + + LUXEMBOURG + LU + + + + MACAO + MO + + + + MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF + MK + + + + MADAGASCAR + MG + + + + MALAWI + MW + + + + MALAYSIA + MY + + + + MALDIVES + MV + + + + MALI + ML + + + + MALTA + MT + + + + MARSHALL ISLANDS + MH + + + + MARTINIQUE + MQ + + + + MAURITANIA + MR + + + + MAURITIUS + MU + + + + MAYOTTE + YT + + + + MEXICO + MX + + + + MICRONESIA, FEDERATED STATES OF + FM + + + + MOLDOVA, REPUBLIC OF + MD + + + + MONACO + MC + + + + MONGOLIA + MN + + + + MONTENEGRO + ME + + + + MONTSERRAT + MS + + + + MOROCCO + MA + + + + MOZAMBIQUE + MZ + + + + MYANMAR + MM + + + + NAMIBIA + NA + + + + NAURU + NR + + + + NEPAL + NP + + + + NETHERLANDS + NL + + + + NEW CALEDONIA + NC + + + + NEW ZEALAND + NZ + + + + NICARAGUA + NI + + + + NIGER + NE + + + + NIGERIA + NG + + + + NIUE + NU + + + + NORFOLK ISLAND + NF + + + + NORTHERN MARIANA ISLANDS + MP + + + + NORWAY + NO + + + + OMAN + OM + + + + PAKISTAN + PK + + + + PALAU + PW + + + + PALESTINE, STATE OF + PS + + + + PANAMA + PA + + + + PAPUA NEW GUINEA + PG + + + + PARAGUAY + PY + + + + PERU + PE + + + + PHILIPPINES + PH + + + + PITCAIRN + PN + + + + POLAND + PL + + + + PORTUGAL + PT + + + + PUERTO RICO + PR + + + + QATAR + QA + + + + RÉUNION + RE + + + + ROMANIA + RO + + + + RUSSIAN FEDERATION + RU + + + + RWANDA + RW + + + + SAINT BARTHÉLEMY + BL + + + + SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA + SH + + + + SAINT KITTS AND NEVIS + KN + + + + SAINT LUCIA + LC + + + + SAINT MARTIN (FRENCH PART) + MF + + + + SAINT PIERRE AND MIQUELON + PM + + + + SAINT VINCENT AND THE GRENADINES + VC + + + + SAMOA + WS + + + + SAN MARINO + SM + + + + SAO TOME AND PRINCIPE + ST + + + + SAUDI ARABIA + SA + + + + SENEGAL + SN + + + + SERBIA + RS + + + + SEYCHELLES + SC + + + + SIERRA LEONE + SL + + + + SINGAPORE + SG + + + + SINT MAARTEN (DUTCH PART) + SX + + + + SLOVAKIA + SK + + + + SLOVENIA + SI + + + + SOLOMON ISLANDS + SB + + + + SOMALIA + SO + + + + SOUTH AFRICA + ZA + + + + SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS + GS + + + + SOUTH SUDAN + SS + + + + SPAIN + ES + + + + SRI LANKA + LK + + + + SUDAN + SD + + + + SURINAME + SR + + + + SVALBARD AND JAN MAYEN + SJ + + + + SWAZILAND + SZ + + + + SWEDEN + SE + + + + SWITZERLAND + CH + + + + SYRIAN ARAB REPUBLIC + SY + + + + TAIWAN, PROVINCE OF CHINA + TW + + + + TAJIKISTAN + TJ + + + + TANZANIA, UNITED REPUBLIC OF + TZ + + + + THAILAND + TH + + + + TIMOR-LESTE + TL + + + + TOGO + TG + + + + TOKELAU + TK + + + + TONGA + TO + + + + TRINIDAD AND TOBAGO + TT + + + + TUNISIA + TN + + + + TURKEY + TR + + + + TURKMENISTAN + TM + + + + TURKS AND CAICOS ISLANDS + TC + + + + TUVALU + TV + + + + UGANDA + UG + + + + UKRAINE + UA + + + + UNITED ARAB EMIRATES + AE + + + + UNITED KINGDOM + GB + + + + UNITED STATES + US + + + + UNITED STATES MINOR OUTLYING ISLANDS + UM + + + + URUGUAY + UY + + + + UZBEKISTAN + UZ + + + + VANUATU + VU + + + + VENEZUELA, BOLIVARIAN REPUBLIC OF + VE + + + + VIET NAM + VN + + + + VIRGIN ISLANDS, BRITISH + VG + + + + VIRGIN ISLANDS, U.S. + VI + + + + WALLIS AND FUTUNA + WF + + + + WESTERN SAHARA + EH + + + + YEMEN + YE + + + + ZAMBIA + ZM + + + + ZIMBABWE + ZW + + + + diff --git a/static/css/app.css b/static/css/app.css index 1286d42..22bbd52 100644 --- a/static/css/app.css +++ b/static/css/app.css @@ -6,14 +6,9 @@ body { margin: 1em auto 6em; } #biglogo { - width:75%; -} -.dark-panel { - background: -moz-linear-gradient(center top, #222222 0%, #313331 100%); - border: 5px solid #999999; - border-radius: 4px; - box-shadow: 0 2px 5px rgba(0,0,0,0.25); - color: #fff; + width:65%; + max-width:650px; + min-width:250px; } .uk-navbar-brand > img, .uk-navbar-flip > img { height:35px; @@ -58,3 +53,30 @@ footer { #streams-online > .uk-article > a > h4 { margin:0px; } +#tsviewer > .uk-modal-dialog { + max-height: 80%; + overflow-y: scroll; +} + +.ts_num { + color: #D9A859; +} +.dn-streamer, .dn-streamer-offline { + display: inline-block; + width: 110px; + padding: 5px; + margin: 5px; +} +.dn-streamer-offline > img { + height:50px; +} + +.dn-streamer-hover { + background:red; +} + +.dn-hero-icon { + background:#000; + padding:4px; + margin:2px; +} diff --git a/static/css/heropedia.css b/static/css/heropedia.css index 06a8a00..41d4326 100644 --- a/static/css/heropedia.css +++ b/static/css/heropedia.css @@ -13,7 +13,7 @@ background-repeat:no-repeat; overflow:visible; text-transform:uppercase; - color: rgba(105,211,50,0.75); + color: black; padding:6px 10px 15px 40px; } #tavernAgility{ diff --git a/static/css/ts3_viewer.css b/static/css/ts3_viewer.css index 5e667ba..a840a46 100644 --- a/static/css/ts3_viewer.css +++ b/static/css/ts3_viewer.css @@ -20,11 +20,10 @@ { font-family: sans-serif; font-size: 14px; - white-space: nowrap; + white-space: normal; width: 100%; line-height: 1; - overflow-x: hidden; - overflow-y: scroll; + overflow: hidden; } .tswv-link diff --git a/teamspeak.py b/teamspeak.py index 61ab5e9..6c2c564 100644 --- a/teamspeak.py +++ b/teamspeak.py @@ -8,10 +8,10 @@ from flask import url_for from bs4 import BeautifulSoup from app import app -from models import TeamspeakData def getTeamspeakWindow(window=605800): current_time = time.time() + from models import TeamspeakData return TeamspeakData.query.filter(TeamspeakData.time < current_time, TeamspeakData.time > current_time-window).order_by(TeamspeakData.time).all() def create_teamspeak_viewer(): @@ -159,8 +159,11 @@ def create_teamspeak_viewer(): return "error: %s" % inst def get_ISO3166_mapping(): - data = requests.get('http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_xml.html') - xml = ElementTree.fromstring(data.text.encode('utf-8')) + #data = requests.get(url_for('static', filename='country_codes.xml')) + #xml = ElementTree.fromstring(data.text.encode('utf-8')) + with open('app/static/country_codes.xml', mode='r') as d: + data = d.read() + xml = ElementTree.fromstring(data) d = dict() for entry in xml.findall('ISO_3166-1_Entry'): d[entry.find('ISO_3166-1_Alpha-2_Code_element').text] = entry.find('ISO_3166-1_Country_name').text diff --git a/templates/hero_random.html b/templates/hero_random.html new file mode 100644 index 0000000..6e8f754 --- /dev/null +++ b/templates/hero_random.html @@ -0,0 +1,87 @@ +{% extends "layout.html" %} +{% block head %} + +{% endblock %} + +{% block title %} A-Z Challenge: {{ user.nickname }}{% endblock %} + +{% block content %} +{% set taverns = heropedia() %} +

{{ user.nickname }}'s A-Z Challenge

+
+
+
+

Current Hero

+

{{ user.random_hero['localized_name'] }}

+ + +

+ Heroes Completed: {{ user.random_heroes.completed | length }}
+ Heroes Left: {{ total_hero_pool() - user.random_heroes.completed|length }} + +

+ + {% if g.user and g.user.steamid == user.steamid %} +
+ + + Completed! + Skip +
+ {% endif %} +
+
+
x1
+

Completed

+ {% for hero in user.random_heroes.completed %} + + {% endfor %} +

+

+
+
+ +
    +
  • + + {% for hero in taverns[0][1] + taverns[3][1] %} + + {% endfor %} +
  • +
  • + + {% for hero in taverns[1][1] + taverns[4][1] %} + + {% endfor %} +
  • +
  • + + {% for hero in taverns[2][1] + taverns[5][1] %} + + {% endfor %} +
  • +
+
+
+{% endblock %} + +{% if g.user and g.user.id == user.id %} +{% block pagescripts %} + +{% endblock %} +{% endif %} diff --git a/templates/index.html b/templates/index.html index 704f023..49a7f21 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,163 +5,128 @@ {% block title %}Dota Noobs{% endblock %} {% block content %} -{% cache 60*5 %} +{#{% cache 60*5 %}#} {% set teamspeak_data = get_teamspeak_window() %} -
-
-
-

Who Are The Doobs!?

-

Welcome to DotaNoobs! We are a community formed by a group of redditors in an effort to provide a fun and rage-free environment for Dota2 players of all skill levels to enjoy the game and learn from each other. We have a TeamSpeak server open to the public for voice communication; hopping into the server is the best way to get involved, so click on "Server" to the right to get started.

-
-

Be sure to visit the forum board to keep in touch with the community even when not playing. Create an account, introduce yourself, and chat about all things DotA.

-

There is a "Dota Noobs" chat room inside the game client, and a "DotaNoobs" guild to help organzie games outside of TeamSpeak. Ask an admin for an invite today!

-
- - -
-
-
-
-
Connect to Teamspeak
-

Our TeamSpeak Server

-
    -
  • Current Users: {{ ts3_current_clients() }}
  • -
  • Active Countries: {{ ts3_countries_active(teamspeak_data) }}
  • -
- - Statistics - -
- - -

Events

- {# - {% if active_event %} - - {% endif %} - {% if upcoming_event %} - - {% else %} - No events planned for the near future. Suggest one on the forum! - {% endif %} - #} +
+
+

Events

+ {# + {% if active_event %} + + {% endif %} + {% if upcoming_event %} + + {% else %} No events planned for the near future. Suggest one on the forum! + {% endif %} + #} + No events planned for the near future. Suggest one on the forum! +
+
+
Users
+

Teamspeak

+
+
+

Users
{{ ts3_current_clients() }}

+
+
+

Online

+
+
+

Countries
{{ ts3_countries_active(teamspeak_data) }}

+
-
+ + Connect + Stats + Download + +
{{ ts3_viewer() | safe }}
-
-
-
-
-

News and Announcements

- {% for news in latest_news %} - - {% endfor %} -
+
- {# -
-
-
View All Events
-

Events

- {% if active_event %} - - {% endif %} - {% if upcoming_event %} -
-

Next Event

- {{ upcoming_event.name }} - + +
+

News and Announcements

+ {% for news in latest_news %} + - {% else %} - No events planned for the near future. Suggest one on the forum! - {% endif %} - No events planned for the near future. Suggest one on the forum! -
-
- #} -
-
-

Live Streams

-
    - -
      -
      + {% endfor %}
      -
      -{% endcache %} + +{#{% endcache %}#} {% endblock %} {% block pagescripts %} {% endblock %} diff --git a/templates/layout.html b/templates/layout.html index 53766c3..05b2a73 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -10,6 +10,7 @@ + @@ -22,36 +23,18 @@