From 92d45841f329cae7bebda1cdb96131e15da1d0bf Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Sun, 22 Oct 2017 21:03:36 +0200 Subject: [PATCH] meal finilising and planing --- kuk.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/kuk.py b/kuk.py index 68a6c24..66f4f66 100644 --- a/kuk.py +++ b/kuk.py @@ -3,6 +3,7 @@ import operator import json from flask import Flask, Response, redirect, url_for, request, session, abort, render_template from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user, current_user +import datetime app = Flask(__name__) #config @@ -60,7 +61,6 @@ class Person(UserMixin): return self.__dict__ mealHistory = {} - class Meal(object): global mealHistory def __init__(self): @@ -161,12 +161,17 @@ login_manager.login_view = "login" @login_required def index(): meal = Meal.getCurrent() - - cook = {} - cook['name'] = meal.kuk - cook['confirmed'] = 'yes' - - return render_template('index.html', leaderboard=Person.leaderboard(), cook=cook, eaters=meal.eaters) + if meal.accounted == 'no': + cook = {} + if meal.kuk[-1] == '?': #no kuk confirmed + cook['name'] = meal.kuk[:-1] + cook['confirmed'] = 'no' + else: + cook['name'] = meal.kuk + cook['confirmed'] = 'yes' + return render_template('index.html', leaderboard=Person.leaderboard(), cook=cook, eaters=meal.eaters) + else: + return "no meal planed :(" # somewhere to login @app.route("/login", methods=["GET", "POST"]) @@ -195,6 +200,7 @@ def addme(): meal = Meal.getCurrent() if current_user.name not in meal.eaters: meal.eaters.append(current_user.name) + save() return Response('

Have a nice meal!

') else: return Response('

only one meal per person!

') @@ -206,9 +212,42 @@ def removeme(): meal = Meal.getCurrent() if current_user.name in meal.eaters: meal.eaters.remove(current_user.name) - return Response('

no food for you!

') + save() + return '

no food for you!

' + else: + return '

insert joke here

' + +# make a new meal +@app.route("/volunteer") +@login_required +def volunteer(): + meal = Meal.getCurrent() + if meal.kuk[-1] == '?': + meal.kuk = current_user.name + save() + return '

we commend you for your bravery!

' else: - return Response('

insert joke here

') + return '

2 cooks is 1 too many

' + +# finishing the meal +@app.route("/finish") +@login_required +def finish(): + meal = Meal.getCurrent() + meal.account() + save() + return '

Meal closed!

' + +# make a new meal +@app.route("/plan") +@login_required +def plan(): + meal = Meal.new('someday') + leaderboard = Person.leaderboard() + leaders = [p for p in leaderboard if p['score'] == leaderboard[0]['score']] + meal.kuk = random.choice(leaders)['name'] + '?' + save() + return '

meal waiting!

' # somewhere to logout @app.route("/logout") @@ -217,7 +256,6 @@ def logout(): logout_user() return Response('

Logged out

') - # handle login failed @app.errorhandler(401) def page_not_found(e):