|
|
@ -3,6 +3,7 @@ import operator
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
from flask import Flask, Response, redirect, url_for, request, session, abort, render_template
|
|
|
|
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
|
|
|
|
from flask_login import LoginManager, UserMixin, login_required, login_user, logout_user, current_user
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
app = Flask(__name__)
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
#config
|
|
|
|
#config
|
|
|
@ -60,7 +61,6 @@ class Person(UserMixin):
|
|
|
|
return self.__dict__
|
|
|
|
return self.__dict__
|
|
|
|
|
|
|
|
|
|
|
|
mealHistory = {}
|
|
|
|
mealHistory = {}
|
|
|
|
|
|
|
|
|
|
|
|
class Meal(object):
|
|
|
|
class Meal(object):
|
|
|
|
global mealHistory
|
|
|
|
global mealHistory
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
@ -161,12 +161,17 @@ login_manager.login_view = "login"
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def index():
|
|
|
|
def index():
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
|
|
|
|
if meal.accounted == 'no':
|
|
|
|
cook = {}
|
|
|
|
cook = {}
|
|
|
|
|
|
|
|
if meal.kuk[-1] == '?': #no kuk confirmed
|
|
|
|
|
|
|
|
cook['name'] = meal.kuk[:-1]
|
|
|
|
|
|
|
|
cook['confirmed'] = 'no'
|
|
|
|
|
|
|
|
else:
|
|
|
|
cook['name'] = meal.kuk
|
|
|
|
cook['name'] = meal.kuk
|
|
|
|
cook['confirmed'] = 'yes'
|
|
|
|
cook['confirmed'] = 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('index.html', leaderboard=Person.leaderboard(), cook=cook, eaters=meal.eaters)
|
|
|
|
return render_template('index.html', leaderboard=Person.leaderboard(), cook=cook, eaters=meal.eaters)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return "no meal planed :("
|
|
|
|
|
|
|
|
|
|
|
|
# somewhere to login
|
|
|
|
# somewhere to login
|
|
|
|
@app.route("/login", methods=["GET", "POST"])
|
|
|
|
@app.route("/login", methods=["GET", "POST"])
|
|
|
@ -195,6 +200,7 @@ def addme():
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
if current_user.name not in meal.eaters:
|
|
|
|
if current_user.name not in meal.eaters:
|
|
|
|
meal.eaters.append(current_user.name)
|
|
|
|
meal.eaters.append(current_user.name)
|
|
|
|
|
|
|
|
save()
|
|
|
|
return Response('<p>Have a nice meal!</p>')
|
|
|
|
return Response('<p>Have a nice meal!</p>')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return Response('<p>only one meal per person!</p>')
|
|
|
|
return Response('<p>only one meal per person!</p>')
|
|
|
@ -206,9 +212,42 @@ def removeme():
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
if current_user.name in meal.eaters:
|
|
|
|
if current_user.name in meal.eaters:
|
|
|
|
meal.eaters.remove(current_user.name)
|
|
|
|
meal.eaters.remove(current_user.name)
|
|
|
|
return Response('<p>no food for you!</p>')
|
|
|
|
save()
|
|
|
|
|
|
|
|
return '<p>no food for you!</p>'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return Response('<p>insert joke here</p>')
|
|
|
|
return '<p>insert joke here</p>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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 '<p>we commend you for your bravery!</p>'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return '<p>2 cooks is 1 too many</p>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# finishing the meal
|
|
|
|
|
|
|
|
@app.route("/finish")
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def finish():
|
|
|
|
|
|
|
|
meal = Meal.getCurrent()
|
|
|
|
|
|
|
|
meal.account()
|
|
|
|
|
|
|
|
save()
|
|
|
|
|
|
|
|
return '<p>Meal closed!</p>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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 '<p>meal waiting!</p>'
|
|
|
|
|
|
|
|
|
|
|
|
# somewhere to logout
|
|
|
|
# somewhere to logout
|
|
|
|
@app.route("/logout")
|
|
|
|
@app.route("/logout")
|
|
|
@ -217,7 +256,6 @@ def logout():
|
|
|
|
logout_user()
|
|
|
|
logout_user()
|
|
|
|
return Response('<p>Logged out</p>')
|
|
|
|
return Response('<p>Logged out</p>')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# handle login failed
|
|
|
|
# handle login failed
|
|
|
|
@app.errorhandler(401)
|
|
|
|
@app.errorhandler(401)
|
|
|
|
def page_not_found(e):
|
|
|
|
def page_not_found(e):
|
|
|
|