
On Tue, Apr 09 2019, Tomas Prochazka wrote:
The patch solves the problem of separate counting of individual types drinks. --- app.py | 15 +++++++++++++-- coffee_db.py | 11 ++--------- templates/user.html | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/app.py b/app.py index 62f79b8..36f10e7 100644 --- a/app.py +++ b/app.py @@ -51,10 +51,21 @@ def logout(): def user(): if "uid" in session: uid = session["uid"] + count=0 + count_mate=0 + data = db.drink_count(uid, 0) + if data != []: + key , value = zip(*data) + d = dict(zip(key,value)) + if "Club-Mate" in d: + count_mate=d["Club-Mate"] + if "Coffee" in d: + count=d["Coffee"]
Tohle je pořád zbytečně složitý. Když v drink_count() bude: return dict(c.execute("SELECT CASE WHEN flavor LIKE 'Club%' THEN 'Club-Mate' ELSE 'Coffee' END AS drink,COUNT() FROM coffees GROUP BY drink")) tak sem napíšeš: counts = db.drink_count(uid, 0)
return render_template('user.html', name=db.get_name(uid), flavors=[_name for (_name, _ord) in db.flavors()], - count=db.coffee_count(uid, 0), + count=count, + count_mate=count_mate,
a tady: count=counts.get("Coffee", 0) count_mate=counts.get("Club-Mate", 0) -Michal