2022-12-08 20:41:30 +01:00
|
|
|
import pickle
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
import humanize
|
2019-01-30 17:54:05 +01:00
|
|
|
from flask import Flask, render_template, request, redirect, url_for
|
2022-12-08 20:41:30 +01:00
|
|
|
from os.path import exists
|
2019-01-30 17:54:05 +01:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Person:
|
2022-12-08 20:41:30 +01:00
|
|
|
statusses = [
|
|
|
|
"Pannenkoek besteld",
|
|
|
|
"Pannenkoek aan het bakken",
|
|
|
|
"Pannenkoek klaar",
|
|
|
|
"Pannenkoek afgegeven",
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, name, remark="", order_time=None):
|
2019-01-30 17:54:05 +01:00
|
|
|
self.name = name
|
|
|
|
self.remark = remark.strip()
|
|
|
|
self.status = 0
|
2022-12-08 20:41:30 +01:00
|
|
|
self.order_time = order_time
|
2019-01-30 17:54:05 +01:00
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
def get_remark(self):
|
2019-01-30 17:54:05 +01:00
|
|
|
return "({})".format(self.remark) if self.remark else self.remark
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
def get_name(self):
|
2019-01-30 17:54:05 +01:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
2019-01-30 18:37:09 +01:00
|
|
|
return self.name.lower() == other.name.lower()
|
2019-01-30 17:54:05 +01:00
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
def get_status(self):
|
2019-01-30 17:54:05 +01:00
|
|
|
return self.statusses[self.status]
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
def next_status(self):
|
2019-01-30 17:54:05 +01:00
|
|
|
return self.statusses[self.status + 1]
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
def order_time_humanized(self):
|
|
|
|
return humanize.naturaltime(self.order_time)
|
|
|
|
|
2019-01-30 17:54:05 +01:00
|
|
|
def __str__(self):
|
|
|
|
return "Persoon: {} met status: {}".format(self.name, self.status)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
people_filename = "people.pickle"
|
2019-01-30 17:54:05 +01:00
|
|
|
people = []
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
if exists(people_filename):
|
|
|
|
people_file = open(people_filename, "rb")
|
|
|
|
people = pickle.load(people_file)
|
|
|
|
people_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def save_people():
|
|
|
|
people_file = open(people_filename, "wb")
|
|
|
|
pickle.dump(people, people_file)
|
|
|
|
people_file.close()
|
|
|
|
|
2019-01-30 17:54:05 +01:00
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def home():
|
|
|
|
return render_template("home.html", people=people)
|
|
|
|
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
@app.route("/status_update", methods=["POST", "GET"])
|
|
|
|
def status_update():
|
2019-01-30 18:37:09 +01:00
|
|
|
if people and request.method == "POST":
|
2019-02-14 22:29:25 +01:00
|
|
|
result = request.form
|
|
|
|
if "index" in result:
|
2019-02-13 23:29:58 +01:00
|
|
|
index = int(request.form["index"])
|
|
|
|
people[index].status += 1
|
|
|
|
if people[index].status == 3:
|
|
|
|
people.remove(people[index])
|
2019-02-14 22:29:25 +01:00
|
|
|
if "name" in result:
|
2019-02-13 23:29:58 +01:00
|
|
|
index = people.index(Person(request.form["name"]))
|
|
|
|
print(index)
|
|
|
|
people[index].status += 1
|
|
|
|
if people[index].status == 3:
|
|
|
|
people.remove(people[index])
|
2022-12-08 20:41:30 +01:00
|
|
|
save_people()
|
2019-01-30 17:54:05 +01:00
|
|
|
return redirect("/")
|
|
|
|
|
|
|
|
|
2022-12-08 20:41:30 +01:00
|
|
|
@app.route("/add_person", methods=["POST", "GET"])
|
|
|
|
def add_person():
|
2019-01-30 17:54:05 +01:00
|
|
|
if request.method == "POST":
|
|
|
|
result = request.form
|
2022-12-08 20:41:30 +01:00
|
|
|
if result["name"]:
|
|
|
|
new_person = Person(
|
|
|
|
result["name"], result["remark"], order_time=datetime.now()
|
|
|
|
)
|
|
|
|
if new_person not in people:
|
|
|
|
people.append(new_person)
|
|
|
|
save_people()
|
2019-01-30 17:54:05 +01:00
|
|
|
return redirect("/")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|