@ -82,6 +82,36 @@ def getUpcomingMeals():
r . close ( )
return meals
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; '
r = db_engine . execute ( text ( query ) , meal_id = meal_id )
meals = [ ]
for row in r :
meals . append ( dict ( row ) )
r . close ( )
if len ( meals ) == 0 :
return None
meal = meals [ 0 ]
seconds_to_deadline = ( meal [ ' selection_deadline ' ] - datetime . datetime . now ( ) ) . total_seconds ( )
if seconds_to_deadline < 0 :
meal [ ' friendly_selection_deadline ' ] = ' '
elif seconds_to_deadline > 3600 :
hours_td = round ( seconds_to_deadline / 3600 )
days_td = int ( hours_td / 24 )
hours_td = hours_td % 24
meal [ ' friendly_selection_deadline ' ] = str ( days_td ) + ' days ' + str ( hours_td ) + ' hours '
else :
meal [ ' friendly_selection_deadline ' ] = str ( round ( seconds_to_deadline / 60 ) ) + ' minutes '
meal [ ' meal_time ' ] = meal [ ' meal_date ' ] . strftime ( ' % H: % M ' )
meal [ ' meal_friendly_date ' ] = meal [ ' meal_date ' ] . strftime ( ' % A %d % B ' )
meal [ ' candidate ' ] = ' davide '
if ( meal [ ' meal_date ' ] - datetime . datetime . now ( ) ) . total_seconds ( ) < 0 :
meal [ ' needs_confirmation ' ] = True
else :
meal [ ' needs_confirmation ' ] = False
return meal
# adding to meal
@app.route ( " /addme " )
@login_required
@ -102,6 +132,15 @@ def addme():
def index ( ) :
return render_template ( ' meal_list.html ' , leaderboard = getLeaderboard ( ) , meals = getUpcomingMeals ( ) , now = datetime . datetime . now ( ) )
@app.route ( ' /view_meal ' )
def view_meal ( ) :
meal_id = request . args . get ( ' meal ' )
meal = getMeal ( meal_id )
if meal == None :
return abort ( 400 )
print ( meal )
return render_template ( ' index.html ' , leaderboard = getLeaderboard ( ) , meal = meal )
@app.route ( ' /login ' , methods = [ ' GET ' , ' POST ' ] )
def login ( ) :
if request . method == ' POST ' :