summaryrefslogtreecommitdiff
path: root/jimbrella/web.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-24 23:12:27 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-24 23:12:27 +0800
commit18b4424faba782e136202ab4d41086e79ace1bd7 (patch)
treee003e292e3626332b54e7bb79444d3b0c467d713 /jimbrella/web.py
parent0ed10326a182d6d37845cf5eb074e3e505d403cf (diff)
Admin can now modify database from web console
Diffstat (limited to 'jimbrella/web.py')
-rw-r--r--jimbrella/web.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/jimbrella/web.py b/jimbrella/web.py
index 4237055..434de57 100644
--- a/jimbrella/web.py
+++ b/jimbrella/web.py
@@ -1,4 +1,4 @@
-from flask import Flask, request, render_template
+from flask import Flask, request, render_template, redirect, url_for
from user_agents import parse as user_agent
from .database import Database
from .config import *
@@ -25,12 +25,33 @@ def admin_index():
@app.route("/admin/umbrellas")
def admin_umbrellas():
umbrellas = db.read()
+ edit = request.args.get("edit")
return render_template(
"admin/umbrellas.html",
umbrellas=umbrellas,
+ edit=int(edit) if edit else None,
mobile=user_agent(request.user_agent.string).is_mobile,
)
+@app.route("/admin/umbrellas/edit", methods=["POST"])
+def admin_umbrellas_edit():
+ data = {}
+ for key in [
+ "serial",
+ "alias",
+ "status",
+ "tenant_name",
+ "tenant_id",
+ "tenant_phone",
+ "tenant_email",
+ "lent_at",
+ ]:
+ data[key] = request.form.get(key)
+
+ db.update(data)
+ return redirect("/admin/umbrellas")
+
+
if __name__ == "__main__":
app.run()