From 54787f68d5740d85c769202331d6a2a78f896f88 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Fri, 30 Nov 2018 23:47:22 +0100 Subject: [PATCH] Temportaty ugly hack --- kukv1.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kukv1.py b/kukv1.py index 99a8aa6..c0b4fe9 100644 --- a/kukv1.py +++ b/kukv1.py @@ -24,7 +24,8 @@ users = {} class User(UserMixin): def __init__(self, name): self.name = name - self.id = -1 + self.id = name + self.user_id = -1 @staticmethod def get(name): @@ -73,6 +74,7 @@ def getUpcomingMeals(): meals[-1]['selection_deadline'] = str(round(seconds_to_deadline / 60)) + ' minutes' meals[-1]['meal_time'] = meals[-1]['meal_date'].strftime('%H:%M') meals[-1]['meal_date'] = meals[-1]['meal_date'].strftime('%A %d %B') + meals[-1]['candidate'] = 'davide' r.close() return meals @@ -82,7 +84,7 @@ def getUpcomingMeals(): def addme(): meal_id = request.args.get('meal') query = 'select :user_id = any (eaters) from meals where id =:meal_id;' - r = db_engine.execute(text(query), user_id=current_user.id, meal_id = meal_id) + r = db_engine.execute(text(query), user_id=current_user.user_id, meal_id = meal_id) results = [] for row in r: results.append(dict(row)) @@ -93,8 +95,9 @@ def addme(): return render_template('appresponse.html', message='Only one meal per person!') @app.route('/') +@login_required def index(): - return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), current_user_name='Wille') + return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals()) @app.route('/login', methods=['GET', 'POST']) def login(): @@ -109,7 +112,7 @@ def login(): print(len(users)) if len(result) > 0: u = User.get(username) - u.id = result[0]['id'] + u.user_id = result[0]['id'] login_user(u) return redirect(request.args.get("next")) return abort(401)