69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
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__)
|
|
|
|
|
|
def execute_query(query):
|
|
conn = sqlite3.connect('user.db')
|
|
c = conn.cursor()
|
|
|
|
# Insert a row of data
|
|
try:
|
|
c.execute(query)
|
|
except:
|
|
print("An sql execute error occured")
|
|
|
|
# Save (commit) the changes
|
|
conn.commit()
|
|
|
|
# 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()
|
|
|
|
|
|
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", orders=fetch_orders())
|
|
|
|
|
|
@app.route("/execute", methods=["POST"])
|
|
def execute():
|
|
content = request.json
|
|
print("Query : ", content)
|
|
execute_query(content["lecode"])
|
|
return redirect("/")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|