Checking if user is already eating

master
Davide Bongiovanni 6 years ago
parent 89c27077fd
commit 6c691e1aae

@ -87,20 +87,20 @@ def getUpcomingMeals():
@login_required @login_required
def addme(): def addme():
meal_id = request.args.get('meal') meal_id = request.args.get('meal')
query = 'select :user_id = any (eaters) from meals where id =:meal_id;' query = 'select :user_id = any (eaters) as is_eater from meals where id =:meal_id;'
r = db_engine.execute(text(query), user_id=current_user.user_id, meal_id = meal_id) r = db_engine.execute(text(query), user_id=current_user.user_id, meal_id = meal_id)
results = [] results = []
for row in r: for row in r:
results.append(dict(row)) results.append(dict(row))
if 1==1: if not results['is_eater']:
return render_template('appresponse.html', message='Have a nice meal ' + meal_id + " mister " + str(current_user.name) ) return render_template('appresponse.html', message='Have a nice meal ' + meal_id + " mister " + str(current_user.name) )
else: else:
return render_template('appresponse.html', message='Only one meal per person!') return render_template('appresponse.html', message='You are already a registered eater')
@app.route('/') @app.route('/')
def index(): def index():
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals()) return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), now=datetime.datetime.now())
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
def login(): def login():

Loading…
Cancel
Save