From b2f84a27cd247e48dacbf28f22b80bddf18bc58a Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Tue, 16 Jun 2026 09:09:05 -0400 Subject: [PATCH] Add comments field --- app.py | 35 +++++++++++++++++++++++------------ templates/index.html | 13 +++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index a70e85a..d118c73 100644 --- a/app.py +++ b/app.py @@ -34,6 +34,7 @@ def initialize_database(): entrytype TEXT NOT NULL CHECK(entrytype IN ('in', 'out')), ts TEXT NOT NULL, paid BOOLEAN NOT NULL DEFAULT FALSE, + comments TEXT, FOREIGN KEY(user_id) REFERENCES users(id) ) """) @@ -57,17 +58,23 @@ def parse_iso_datetime(value): def utc_now(): return datetime.now(timezone.utc) -def create_entry(user_id, entry_type, client_timestamp=None): +def create_entry(user_id, entry_type, client_timestamp=None, comments=None): conn = get_db_connection() cursor = conn.cursor() if client_timestamp: timestamp = parse_iso_datetime(client_timestamp) else: timestamp = utc_now() - cursor.execute(""" - INSERT INTO entries (user_id, entrytype, ts, paid) - VALUES (?, ?, ?, ?) - """, (user_id, entry_type, timestamp.isoformat(), False)) + if comments: + cursor.execute(""" + INSERT INTO entries (user_id, entrytype, ts, paid, comments) + VALUES (?, ?, ?, ?, ?) + """, (user_id, entrytype, timestamp.isoformat(), False, comments)) + else: + cursor.execute(""" + INSERT INTO entries (user_id, entrytype, ts, paid) + VALUES (?, ?, ?, ?) + """, (user_id, entrytype, timestamp.isoformat(), False)) conn.commit() conn.close() @@ -77,7 +84,7 @@ def generate_report(user_id, begin_date, end_date): begin_dt = parse_iso_datetime(begin_date) end_dt = parse_iso_datetime(end_date) cursor.execute(""" - SELECT entrytype, ts, paid + SELECT entrytype, ts, paid, comments FROM entries WHERE user_id = ? AND ts BETWEEN ? AND ? @@ -145,17 +152,20 @@ def index(): selected_user_id = request.form.get("user_id") action = request.form.get("action") client_timestamp = request.form.get("client_timestamp") + comments = request.form.get("comments") if action == "clock_in": create_entry( selected_user_id, "in", - client_timestamp + client_timestamp, + comments ) elif action == "clock_out": create_entry( selected_user_id, "out", - client_timestamp + client_timestamp, + comments ) elif action == "pay": # Update the paid column for all entries for the selected user to True @@ -211,7 +221,7 @@ def api_get_users(): def api_get_entries(): conn = get_db_connection() entries = conn.execute(""" - SELECT id, user_id, entrytype, ts, paid + SELECT id, user_id, entrytype, ts, paid, comments FROM entries ORDER BY ts DESC """).fetchall() @@ -225,15 +235,17 @@ def api_create_entry(): entry_type = data.get("entrytype") client_timestamp = data.get("timestamp") paid = data.get("paid", False) + comments = data.get("comments", "") if entry_type not in ("in", "out", "pay"): return jsonify({ "error": "Invalid entrytype" }), 400 create_entry( user_id, - entry_type, + entrytype, client_timestamp, - paid + paid, + comments ) return jsonify({ "status": "success" @@ -246,4 +258,3 @@ if __name__ == "__main__": port=5000, debug=False ) - diff --git a/templates/index.html b/templates/index.html index 9d4c0b9..69609d2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -149,6 +149,19 @@ + + Comments + + + + + + Report