make it sooooo much better

This commit is contained in:
Maxime Bloch 2019-12-17 06:03:47 +01:00
parent 2e40788bdb
commit 9f147c9c98
No known key found for this signature in database
GPG key ID: CE32A7D95B7D6418
7 changed files with 313 additions and 67 deletions

3
.gitignore vendored
View file

@ -1 +1,4 @@
.idea/
__pycache__/
env/
*.db

2
Makefile Normal file
View file

@ -0,0 +1,2 @@
all:
FLASK_ENV=development FLASK_APP=main.py flask run

93
main.py
View file

@ -1,65 +1,66 @@
from flask import Flask, render_template, request, redirect, url_for
import sqlite3
# create table orders (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, remark TEXT, created_at dat
#etime default current_timestamp, status text default "besteld");
# c = conn.cursor()
# Create table
# c.execute('''CREATE TABLE order
# (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, remark TEXT)''')
# conn.commit()
# conn.close()
app = Flask(__name__)
class Person:
statusses = ["Pannenkoek besteld", "Pannenkoek aan het bakken", "Pannenkoek klaar", "Pannenkoek afgegeven"]
def execute_query(query):
conn = sqlite3.connect('user.db')
c = conn.cursor()
def __init__(self, name, remark=""):
self.name = name
self.remark = remark.strip()
self.status = 0
# Insert a row of data
try:
c.execute(query)
except:
print("An sql execute error occured")
def getRemark(self):
return "({})".format(self.remark) if self.remark else self.remark
# Save (commit) the changes
conn.commit()
def getName(self):
return self.name
def __eq__(self, other):
return self.name.lower() == other.name.lower()
def getStatus(self):
return self.statusses[self.status]
def nextStatus(self):
return self.statusses[self.status + 1]
def __str__(self):
return "Persoon: {} met status: {}".format(self.name, self.status)
def __repr__(self):
return str(self)
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
people = []
def fetch_orders():
conn = sqlite3.connect('user.db')
c = conn.cursor()
c.execute(
"select name, remark, status, id from orders order by created_at")
rows = c.fetchall()
return [{
"name": row[0],
"remark": row[1],
"status": row[2],
"id": row[3]
} for row in rows]
pancake_statuses = ["besteld", "aan_het_bakken", "klaar"]
@app.route("/")
def home():
return render_template("home.html", people=people)
return render_template("home.html", orders=fetch_orders())
@app.route("/statusUpdate", methods=["POST", "GET"])
def statusUpdate():
if people and request.method == "POST":
index = people.index(Person(request.form["name"]))
print(index)
people[index].status += 1
if people[index].status == 3:
people.remove(people[index])
return redirect("/")
@app.route("/addPerson", methods=["POST", "GET"])
def addPerson():
if request.method == "POST":
result = request.form
if result["name"]:
newPerson = Person(result["name"], result["remark"])
if newPerson not in people:
people.append(newPerson)
@app.route("/execute", methods=["POST"])
def execute():
content = request.json
print("Query : ", content)
execute_query(content["lecode"])
return redirect("/")

192
poetry.lock generated Normal file
View file

@ -0,0 +1,192 @@
[[package]]
category = "dev"
description = "Backport of Python 3 csv module"
name = "backports.csv"
optional = false
python-versions = "*"
version = "1.0.7"
[[package]]
category = "dev"
description = "Helpers for building command-line apps"
name = "cli-helpers"
optional = false
python-versions = "*"
version = "1.2.1"
[package.dependencies]
Pygments = ">=1.6"
"backports.csv" = ">=1.0.0"
configobj = ">=5.0.5"
tabulate = ">=0.8.2"
terminaltables = ">=3.0.0"
[[package]]
category = "main"
description = "Composable command line interface toolkit"
name = "click"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "7.0"
[[package]]
category = "dev"
description = "Config file reading, writing and validation."
name = "configobj"
optional = false
python-versions = "*"
version = "5.0.6"
[package.dependencies]
six = "*"
[[package]]
category = "main"
description = "A simple framework for building complex web applications."
name = "flask"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
version = "1.1.1"
[package.dependencies]
Jinja2 = ">=2.10.1"
Werkzeug = ">=0.15"
click = ">=5.1"
itsdangerous = ">=0.24"
[[package]]
category = "main"
description = "Various helpers to pass data to untrusted environments and back."
name = "itsdangerous"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "1.1.0"
[[package]]
category = "main"
description = "A very fast and expressive template engine."
name = "jinja2"
optional = false
python-versions = "*"
version = "2.10.3"
[package.dependencies]
MarkupSafe = ">=0.23"
[[package]]
category = "dev"
description = "CLI for SQLite Databases with auto-completion and syntax highlighting."
name = "litecli"
optional = false
python-versions = "*"
version = "1.2.0"
[package.dependencies]
Pygments = ">=1.6"
cli-helpers = ">=1.0.1"
click = ">=4.1"
configobj = ">=5.0.5"
prompt-toolkit = ">=2.0.0,<2.1.0"
sqlparse = ">=0.2.2,<0.3.0"
[[package]]
category = "main"
description = "Safely add untrusted strings to HTML/XML markup."
name = "markupsafe"
optional = false
python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
version = "1.1.1"
[[package]]
category = "dev"
description = "Library for building powerful interactive command lines in Python"
name = "prompt-toolkit"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
version = "2.0.10"
[package.dependencies]
six = ">=1.9.0"
wcwidth = "*"
[[package]]
category = "dev"
description = "Pygments is a syntax highlighting package written in Python."
name = "pygments"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
version = "2.5.2"
[[package]]
category = "dev"
description = "Python 2 and 3 compatibility utilities"
name = "six"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*"
version = "1.13.0"
[[package]]
category = "dev"
description = "Non-validating SQL parser"
name = "sqlparse"
optional = false
python-versions = "*"
version = "0.2.4"
[[package]]
category = "dev"
description = "Pretty-print tabular data"
name = "tabulate"
optional = false
python-versions = "*"
version = "0.8.6"
[package.dependencies]
wcwidth = "*"
[[package]]
category = "dev"
description = "Generate simple tables in terminals from a nested list of strings."
name = "terminaltables"
optional = false
python-versions = "*"
version = "3.1.0"
[[package]]
category = "dev"
description = "Measures number of Terminal column cells of wide-character codes"
name = "wcwidth"
optional = false
python-versions = "*"
version = "0.1.7"
[[package]]
category = "main"
description = "The comprehensive WSGI web application library."
name = "werkzeug"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "0.16.0"
[metadata]
content-hash = "cedb57d5530f510b56b00c8d54c8beec6fe6f2d9573d1f89eb4c3234c3361a69"
python-versions = "^3.8"
[metadata.hashes]
"backports.csv" = ["1277dfff73130b2e106bf3dd347adb3c5f6c4340882289d88f31240da92cbd6d", "21f6e09bab589e6c1f877edbc40277b65e626262a86e69a70137db714eaac5ce"]
cli-helpers = ["0885ab0a6e0b03f39bcbd6ebd1c439131a94a20d8f5ba2b3e464e9fa05a1a80b", "98db22eaa86827d99ee6af9f5f3923142d04df256425204530842b032849a165", "e8be0d0f079798490e6bc2a46087a045a8e5b64964eceb210bbb7ba1d98baacd"]
click = ["2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13", "5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"]
configobj = ["a2f5650770e1c87fb335af19a9b7eb73fc05ccf22144eb68db7d00cd2bcb0902"]
flask = ["13f9f196f330c7c2c5d7a5cf91af894110ca0215ac051b5844701f2bfd934d52", "45eb5a6fd193d6cf7e0cf5d8a5b31f83d5faae0293695626f539a823e93b13f6"]
itsdangerous = ["321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19", "b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749"]
jinja2 = ["74320bb91f31270f9551d46522e33af46a80c3d619f4a4bf42b3164d30b5911f", "9fe95f19286cfefaa917656583d020be14e7859c6b0252588391e47db34527de"]
litecli = ["94f531aa9da58af559f1944ff09f2f2692dc1ce9ed3b0c8f2acf6107b4e605f6", "a42950fc0e4387b29fbeef28a048d9fb4059327e1e32e90ea8015ee6db8ffea4"]
markupsafe = ["00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", "09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", "09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", "1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", "24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", "29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", "43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", "46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", "500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", "535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", "62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", "6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", "717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", "79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", "7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", "88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", "8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", "98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", "9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", "9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", "ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", "b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", "b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", "b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", "ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", "c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", "cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", "e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"]
prompt-toolkit = ["46642344ce457641f28fc9d1c9ca939b63dadf8df128b86f1b9860e59c73a5e4", "e7f8af9e3d70f514373bf41aa51bc33af12a6db3f71461ea47fea985defb2c31", "f15af68f66e664eaa559d4ac8a928111eebd5feda0c11738b5998045224829db"]
pygments = ["2a3fe295e54a20164a9df49c75fa58526d3be48e14aceba6d6b1e8ac0bfd6f1b", "98c8aa5a9f778fcd1026a17361ddaf7330d1b7c62ae97c3bb0ae73e0b9b6b0fe"]
six = ["1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", "30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"]
sqlparse = ["ce028444cfab83be538752a2ffdb56bc417b7784ff35bb9a3062413717807dec", "d9cf190f51cbb26da0412247dfe4fb5f4098edb73db84e02f9fc21fdca31fed4"]
tabulate = ["5470cc6687a091c7042cee89b2946d9235fe9f6d49c193a4ae2ac7bf386737c8"]
terminaltables = ["f3eb0eb92e3833972ac36796293ca0906e998dc3be91fbe1f8615b331b853b81"]
wcwidth = ["3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e", "f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c"]
werkzeug = ["7280924747b5733b246fe23972186c6b348f9ae29724135a6dfc1e53cea433e7", "e5f4a1f98b52b18a93da705a7458e55afb26f32bff83ff5d19189f92462d65c4"]

16
pyproject.toml Normal file
View file

@ -0,0 +1,16 @@
[tool.poetry]
name = "pannenkoekenwachtrij"
version = "0.1.0"
description = ""
authors = ["Maxime Bloch <me@mcbloch.dev>"]
[tool.poetry.dependencies]
python = "^3.8"
flask = "^1.1"
[tool.poetry.dev-dependencies]
litecli = "^1.2"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

BIN
static/css/bulma-0.8.0.zip Normal file

Binary file not shown.

View file

@ -1,33 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pannenkoekenwachtrij</title>
</head>
<body>
<header>
<h1>Welkom bij de pannenkoekenwachtrij</h1>
<header>
<h1>Welkom bij de pannenkoekenwachtrij</h1>
<form action="/addPerson" method="POST">
<p>Naam van de volgende <input type="text" name="name"></p>
<p>Specifieke opmerkingen <input type="text" name="remark"></p>
<p><input type="submit" value="Persoon toevoegen"></p>
</form>
<form id="addPersonForm">
<p>Naam van de volgende <input type="text" name="name"></p>
<p>Specifieke opmerkingen <input type="text" name="remark"></p>
<p><input type="submit" value="Persoon toevoegen" id="addPersonButton"></p>
</form>
<form action="/statusUpdate" method="POST">
<p>Up te daten persoon <input type="text" name="name"></p>
<p><input type="submit" value="Updaten"></p>
</form>
<h2>Zie hieronder de lijst van personen die een pannenkoek willen</h2>
<table>
{% for person in people %}
<h2>Zie hieronder de lijst van personen die een pannenkoek willen</h2>
<table>
{% for order in orders %}
<tr>
<th>{{ person.getName() + person.getRemark() + ": " }}</th>
<td>{{ "Huidige status: " + person.getStatus() }}</td>
<td><button onclick="start_bakken({{order.id}})">Aan het bakken</button></td>
<td><button onclick="klaar({{order.id}})">Klaar</button></td>
<td><button onclick="dissmiss({{order.id}})">Dismiss</button></td>
<th>{{ order.name + order.remark + ": " }}</th>
<td>{{ "Huidige status: " + order.status }}</td>
</tr>
{% endfor %}
</table>
</header>
{% endfor %}
</table>
</header>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function() {
$("#addPersonButton").click(function(event) {
event.preventDefault();
var form = $("#addPersonForm").serializeArray();
var name = form[0]["value"];
var remark = form[1]["value"];
$.ajax({
type: "POST",
url: '/execute',
contentType: "application/json",
data: JSON.stringify({
"lecode": `insert into orders (name, remark) values ("${name}", "${remark}")`
}),
success: function(data) {
console.log("SUCCESS : ", data);
},
error: function(e) {
console.log("ERROR : ", e);
}
});
});
})
</script>
</body>
</html>
</html>