Marek Baczynski 6 years ago
commit 18d8d2ede9

@ -60,7 +60,7 @@ def getUpcomingMeals():
# meals.append({'id':2, 'kuk':'marek', 'eaters':['davide','sven','david', 'wille'], 'flavor_text':'Grzybowa', 'date':'Sunday 25rd of November', 'selection_deadline':'3 Days 23 hours', 'status':0})
# meals.append({'id':2, 'kuk':'marek', 'eaters':['davide','sven','david', 'wille'], 'flavor_text':'Grzybowa', 'date':'Sunday 25rd of November', 'selection_deadline':'3 Days 23 hours', 'status':0})
# meals.append({'id':2, 'kuk':'marek', 'eaters':['davide','sven','david', 'wille'], 'flavor_text':'Grzybowa', 'date':'Monday 26rd of November', 'selection_deadline':'3 Days 23 hours', 'status':0})
query = 'select foo.id, username as kuk, meal_date, array_agg as eaters, selection_deadline, is_lazy from (select is_lazy, meals.id, kuk, meal_date, selection_deadline, array_agg(username) from meals join users on users.id = any(meals.eaters) where meals.status=0 group by meals.id order by meal_date) as foo join users on kuk=users.id;'
query = 'SELECT foo.id, username AS kuk, meal_date, array_agg AS eaters, selection_deadline, is_lazy FROM (SELECT is_lazy, meals.id, kuk, meal_date, selection_deadline, array_agg(username) FROM meals JOIN users ON users.id = any(meals.eaters) WHERE meals.status=0 GROUP BY meals.id ORDER BY meal_date) AS foo JOIN users ON kuk=users.id;'
r = db_engine.execute(text(query))
meals = []
leaderboard = getLeaderboard()
@ -109,7 +109,7 @@ def applyTempMeal(leaderboard, meal):
return sorted(ld, key=lambda i:(i['score'], i['last_meal'] or datetime.datetime(1970, 1, 1, 0, 0)))
def getMeal(meal_id):
query = 'select foo.id, username as kuk, meal_date, array_agg as eaters, selection_deadline from (select meals.id, kuk, meal_date, selection_deadline, array_agg(username) from meals join users on users.id = any(meals.eaters) where meals.id=:meal_id group by meals.id order by meal_date) as foo join users on kuk=users.id;'
query = 'SELECT foo.id, username AS kuk, meal_date, array_agg AS eaters, selection_deadline FROM (SELECT meals.id, kuk, meal_date, selection_deadline, array_agg(username) FROM meals JOIN users ON users.id = any(meals.eaters) WHERE meals.id=:meal_id GROUP BY meals.id ORDER BY meal_date) AS foo JOIN users ON kuk=users.id;'
r = db_engine.execute(text(query), meal_id=meal_id)
meals = []
for row in r:
@ -143,7 +143,7 @@ def getMeal(meal_id):
@login_required
def addme():
meal_id = request.args.get('meal')
query = 'select :user_id = any (eaters) as is_eater 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)
results = []
for row in r:
@ -159,7 +159,7 @@ def addme():
@login_required
def removeme():
meal_id = request.args.get('meal')
query = 'UPDATE meals SET eaters = array_remove(eaters, :user_id) where id = :meal_id;'
query = 'UPDATE meals SET eaters = array_remove(eaters, :user_id) WHERE id = :meal_id;'
r = db_engine.execute(text(query), user_id=current_user.user_id, meal_id = meal_id)
return render_template('appresponse.html', message='You were removed from that meal')
@ -187,7 +187,7 @@ def meal_planner():
def search_users():
q = request.args.get('q')
s = request.args.get('s')
query = 'select username from users where id>0 and username like :q;'
query = 'SELECT username FROM users WHERE id>0 AND username LIKE :q;'
if s == '1':
r = db_engine.execute(text(query), q=(q+'%'))
else:

Loading…
Cancel
Save