From f3c778048fbdf1fe30022125f070420b8d19da08 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Tue, 24 Dec 2024 23:24:15 +1100 Subject: [PATCH] Add page to confirm deletion and add cancel button on edit page --- app/routes.py | 16 ++++++++++ app/templates/confirm_delete.html | 28 +++++++++++++++++ app/templates/dashboard.html | 52 +++++++++++++++++++++---------- app/templates/edit_reading.html | 14 +++++++-- 4 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 app/templates/confirm_delete.html diff --git a/app/routes.py b/app/routes.py index ef26ffd..731db21 100644 --- a/app/routes.py +++ b/app/routes.py @@ -157,6 +157,22 @@ def edit_reading(reading_id): return render_template('edit_reading.html', form=form, reading=reading) +@main.route('/confirm_delete/', methods=['GET', 'POST']) +@login_required +def confirm_delete(reading_id): + # Fetch the reading to confirm deletion + reading = Reading.query.filter_by(id=reading_id, user_id=current_user.id).first_or_404() + + if request.method == 'POST': + # Handle deletion + db.session.delete(reading) + db.session.commit() + flash('Reading deleted successfully!', 'success') + return redirect(url_for('main.dashboard')) + + return render_template('confirm_delete.html', reading=reading) + + @main.route('/reading//delete', methods=['POST']) @login_required def delete_reading(reading_id): diff --git a/app/templates/confirm_delete.html b/app/templates/confirm_delete.html new file mode 100644 index 0000000..6e3f1c7 --- /dev/null +++ b/app/templates/confirm_delete.html @@ -0,0 +1,28 @@ +{% extends "_layout.html" %} + +{% block content %} +
+

Confirm Deletion

+

Are you sure you want to delete the following reading?

+ + +
+

Timestamp: {{ reading.timestamp.strftime('%d %b %Y, %I:%M %p') }}

+

Systolic: {{ reading.systolic }} mmHg

+

Diastolic: {{ reading.diastolic }} mmHg

+

Heart Rate: {{ reading.heart_rate }} bpm

+
+ + +
+ + Cancel + +
+ +
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index 45b499e..2234459 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -168,14 +168,14 @@
- +
- + @@ -183,28 +183,47 @@ {% for reading in readings %} - - - - + + {% else %} - + {% endfor %} @@ -212,5 +231,6 @@ + {% endblock %} \ No newline at end of file diff --git a/app/templates/edit_reading.html b/app/templates/edit_reading.html index 827a4c6..1ab3342 100644 --- a/app/templates/edit_reading.html +++ b/app/templates/edit_reading.html @@ -45,9 +45,17 @@ {% endfor %} - -
-
Timestamp Blood Pressure (mmHg) Heart RateActionsActions
{{ reading.timestamp.strftime('%d %b %Y, %I:%M %p') - }} + + + {{ reading.timestamp.strftime('%d %b %Y, %I:%M %p') }} + + {{ reading.systolic }}/{{ reading.diastolic }} {{ reading.heart_rate }} + + + {{ reading.heart_rate }} bpm + + Edit -
- {{ delete_form.hidden_tag() }} - -
+ class="inline-flex items-center px-2 py-1 text-sm font-medium text-blue-600 hover:text-blue-800 focus:outline-none focus:ring-2 focus:ring-blue-500"> + + + + Edit + + + + + + + + Delete +
No readings found. + No readings found. +