From 18b4424faba782e136202ab4d41086e79ace1bd7 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sun, 24 Oct 2021 23:12:27 +0800 Subject: Admin can now modify database from web console --- jimbrella/templates/admin/logs.html | 34 ++++++++++++++++++++++++++ jimbrella/templates/admin/umbrellas.html | 42 +++++++++++++++++++++++++++++++- jimbrella/web.py | 23 ++++++++++++++++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 jimbrella/templates/admin/logs.html diff --git a/jimbrella/templates/admin/logs.html b/jimbrella/templates/admin/logs.html new file mode 100644 index 0000000..6f0ed71 --- /dev/null +++ b/jimbrella/templates/admin/logs.html @@ -0,0 +1,34 @@ + + + + JI Umbrella + + + + +

JI Umbrella Logs

+
+ {% include "admin/tabs.html" %} +
+ + + + + + + + + + {% for log in logs %} + + + + + + {% endfor %} + +
DateEventNote
{{ log.date_str }}{{ log.description }}{{ log.note }}
+
+
+ + diff --git a/jimbrella/templates/admin/umbrellas.html b/jimbrella/templates/admin/umbrellas.html index 6bb4af5..15b6f02 100644 --- a/jimbrella/templates/admin/umbrellas.html +++ b/jimbrella/templates/admin/umbrellas.html @@ -15,7 +15,11 @@ {% for umb in umbrellas %} {% if umb.status in ["lent", "overdue"] %} - {{ umb.serial }}
{{ umb.status }} + + {{ umb.serial }}
+ {{ umb.status }}
+ Edit + {{ umb.tenant_name }} {{ umb.tenant_id }} @@ -47,8 +51,40 @@ + {% macro status_opt(umb, status) -%} + + {%- endmacro %} + {% for umb in umbrellas %} + {% if umb.serial == edit %} +
+ + {{ umb.serial }} + + + + + + + + {{ umb.lent_time_ago_str }} + {% if umb.status in ["lent", "overdue"] %} ago {% endif %} + + + + +
+ {% else %} {{ umb.serial }} {{ umb.status }} {{ umb.tenant_name }} @@ -58,6 +94,10 @@ {{ umb.lent_time_ago_str }} {% if umb.status in ["lent", "overdue"] %} ago {% endif %} + + Edit + + {% endif %} {% endfor %} 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() -- cgit v1.2.3