Fix up A-Z stuff.
This commit is contained in:
1 parent
75a6844b9b
commit
237a671171
7 files changed
+43
-61
No files matched your search
+7
-2
@@ -6,7 +6,7 @@ from sqlalchemy.ext.mutable import Mutable
|
||||
|
||||
import board
|
||||
from app import db, app
|
||||
from utils import parse_valve_heropedia, complete_hero_data
|
||||
from utils import parse_valve_heropedia, complete_hero_data, API_DATA
|
||||
|
||||
# Model independant get_or_create
|
||||
def get_or_create_instance(session, model, **kwargs):
|
||||
@@ -73,6 +73,7 @@ class User(db.Model):
|
||||
last_seen = db.Column(db.DateTime)
|
||||
twitch = db.Column(db.String(60))
|
||||
random_heroes = db.Column(MutableDict.as_mutable(Json))
|
||||
az_completions = db.Column(db.Integer)
|
||||
|
||||
public = db.Column(db.Boolean)
|
||||
logo = db.Column(db.Boolean)
|
||||
@@ -94,6 +95,7 @@ class User(db.Model):
|
||||
def __init__(self, steam_id):
|
||||
self.steam_id = steam_id
|
||||
self.random_heroes = {'current':None, 'completed':[]}
|
||||
self.az_completions = 0
|
||||
self.created = datetime.utcnow()
|
||||
self.last_seen = datetime.utcnow()
|
||||
self.bio_text = None
|
||||
@@ -109,7 +111,7 @@ class User(db.Model):
|
||||
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])
|
||||
heroes.extend([complete_hero_data('name', entry['name']) for entry in tavern if entry['name'] not in self.random_heroes['completed']])
|
||||
if heroes:
|
||||
self.random_heroes['current'] = choice(heroes)
|
||||
self.random_heroes = self.random_heroes
|
||||
@@ -128,6 +130,9 @@ class User(db.Model):
|
||||
|
||||
def random_success(self):
|
||||
self.random_heroes['completed'].append(self.random_heroes['current']['name'])
|
||||
if len(API_DATA['result']['heroes']) - len(self.random_heroes['completed']) <= 0:
|
||||
self.az_completions = self.az_completions + 1
|
||||
del self.random_heroes['completed'][:]
|
||||
self.random_heroes['current'] = None
|
||||
self.random_heroes = self.random_heroes
|
||||
db.session.commit()
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</span>
|
||||
</p>
|
||||
|
||||
{% if g.user and g.user.steamid == user.steamid %}
|
||||
{% if g.user and g.user.steam_id == user.steam_id %}
|
||||
<form action="{{ url_for('user_random_hero', userid=g.user.id) }}" method="post" id="random_form" class="uk-margin">
|
||||
<input type="checkbox" name="completed" id="completed_checkbox" style="display:none;">
|
||||
<input type="checkbox" name="skip" id="skip_checkbox" style="display:none;">
|
||||
@@ -31,7 +31,9 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="uk-width-large-2-3 uk-width-medium-1-1 uk-panel uk-text-center uk-margin">
|
||||
<div class="uk-badge uk-panel-badge uk-badge-notification uk-badge-success">x1</div>
|
||||
{% if user.az_completions > 0 %}
|
||||
<div class="uk-badge uk-panel-badge uk-badge-notification uk-badge-success">x{{ user.az_completions }}</div>
|
||||
{% endif %}
|
||||
<h3 class="uk-panel-title">Completed</h3>
|
||||
{% for hero in user.random_heroes.completed %}
|
||||
<img src="{{ url_for('static', filename=hero_image_small(hero)) }}" class="dn-hero-icon" />
|
||||
|
||||
Reference in new issue
Block a user