From 55be2a898b95bb5db14bfd5dba49ac946cee65b2 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 3 Oct 2024 23:13:59 -0400 Subject: [PATCH] Added manual swipe, swipe delete, cleanup, dark theme --- app/static/css/main.css | 3 ++- app/templates/log.html | 18 +++++++++++++++ app/templates/users.html | 1 + app/views.py | 50 +++++++++++++++++++++++++++++++--------- 4 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 app/templates/log.html diff --git a/app/static/css/main.css b/app/static/css/main.css index efb6399..0619564 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -1,6 +1,7 @@ body { + font-family: Roboto, sans-serif; background-color: #242424; - color: #fff; + color: #A6A6A6; } header { diff --git a/app/templates/log.html b/app/templates/log.html new file mode 100644 index 0000000..2d7e1db --- /dev/null +++ b/app/templates/log.html @@ -0,0 +1,18 @@ + + + + + + + Log + + +
+
+ {% for swipe in swipes %} + + {{ swipe['time'] }} | {{ swipe['first_name'] | safe }} | {{ swipe['last_name'] | safe }}
+ {% endfor %} +
+ + diff --git a/app/templates/users.html b/app/templates/users.html index f804bbf..d7a734d 100644 --- a/app/templates/users.html +++ b/app/templates/users.html @@ -20,6 +20,7 @@
+ diff --git a/app/views.py b/app/views.py index 1cc7d43..4e45d7a 100644 --- a/app/views.py +++ b/app/views.py @@ -8,6 +8,8 @@ from datetime import date import json # from flask_login import login_user, login_required, logout_user +after_date = '2024-08-22' + @app.route('/') def index(): return 'No.' @@ -36,6 +38,10 @@ def users(): @app.route('/users/modify', methods=['POST']) def users_modify(): data = request.form + if data['action'] == 'swipe': + swipe = Swipe(data['uuid']) + db.session.add(swipe) + db.session.commit() if data['action'] == 'set_name': if data['first_name'] == '' or data['last_name'] == '': return 'Fill out the form...' @@ -90,17 +96,38 @@ def swipe(): return 'OK' -@app.route('/log', methods=['GET']) +@app.route('/log', methods=['GET', 'POST']) def log(): - swipes = db.session.query(Swipe) - result = '' + global after_date + if request.method == 'POST': + after_date = request.form['after_date'] + swipes = db.session.query(Swipe).filter(Swipe.time >= after_date) + result = [] for swipe in swipes: + print(swipe.__dict__) + first_name = 'WHO DIS' + last_name = swipe.uuid + names = User.query.filter_by(uuid=swipe.uuid).first() if names: - result += f'{swipe.time} | {names.first_name} | {names.last_name}
' - else: - result += f'{swipe.time} | WHO DIS {swipe.uuid}
' - return result + first_name = names.first_name + last_name = names.last_name + result.append({ + 'time': swipe.time, + 'first_name': first_name, + 'last_name': last_name, + 'id': swipe.id}) + return render_template('log.html', swipes=result, after_date=after_date) + +@app.route('/log/modify', methods=['POST']) +def log_modify(): + data = request.form + if 'delete_id' in data: + swipe = Swipe.query.filter_by(id=data['delete_id']).first() + db.session.delete(swipe) + db.session.commit() + + return redirect(url_for('log'), code=302) @app.route('/kiosk', methods=['GET']) def kiosk(): @@ -108,7 +135,7 @@ def kiosk(): @app.route('/kiosk/data', methods=['GET']) def kiosk_data(): - swipes = db.session.query(Swipe).filter(Swipe.time >= '2023-07-16') + swipes = db.session.query(Swipe).filter(Swipe.time >= after_date) counts = {} last_swipes = {} @@ -145,7 +172,7 @@ def kiosk_data(): @app.route('/report', methods=['GET', 'POST']) def report(): - after_date = '2024-08-22' + global after_date if request.method == 'POST': after_date = request.form['after_date'] days = {} @@ -168,7 +195,8 @@ def report(): - result = f'
' + result = '' + result += f'
' result += '' name_query = db.session.query(User) @@ -177,7 +205,7 @@ def report(): for name_obj in name_query: name = f'{name_obj.first_name} {name_obj.last_name}' names.append(name) - result += f'' + result += f'' result += ''
{name}{name}