From bc78e17de6be8619ef41d862f11c04dfa3451536 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Wed, 27 Apr 2022 08:41:18 -0400 Subject: [PATCH] Add Delete Function --- period/cycles.py | 15 ++++++++++++--- period/templates/cycle/index.html | 8 +++++++- period/templates/cycle/update.html | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/period/cycles.py b/period/cycles.py index c6cc0f1..be14b24 100644 --- a/period/cycles.py +++ b/period/cycles.py @@ -54,8 +54,9 @@ def create(): ) else: db.execute( - 'INSERT INTO cycle (start_time, cycle_length) VALUES (?, ?)', - (start_time_stamp, cycle_length) + 'INSERT INTO cycle (start_time)' + ' VALUES (?)', + (start_time.to_datetime_string(),) ) db.commit() return redirect(url_for('index')) @@ -118,4 +119,12 @@ def update(id): ) db.commit() return redirect(url_for('index')) - return render_template('cycle/update.html', cycle=cycle) \ No newline at end of file + return render_template('cycle/update.html', cycle=cycle) + +@bp.route('//delete', methods=('POST',)) +def delete(id): + get_cycle(id) + db = get_db() + db.execute('DELETE FROM cycle WHERE id = ?', (id,)) + db.commit() + return redirect(url_for('index')) \ No newline at end of file diff --git a/period/templates/cycle/index.html b/period/templates/cycle/index.html index e78633a..9602d32 100644 --- a/period/templates/cycle/index.html +++ b/period/templates/cycle/index.html @@ -25,7 +25,13 @@ Ended: {{ cycle['end_time'] }} -

Cycle Length: {{ cycle['cycle_length'] }} days.

+

+ {% if cycle['cycle_length'] %} + Cycle Length: {{ cycle['cycle_length'] }} days. + {% else %} + + {% endif %} +

Edit - {{ cycle['id'] }} {% if not loop.last %} diff --git a/period/templates/cycle/update.html b/period/templates/cycle/update.html index a3f8234..6eb0b24 100644 --- a/period/templates/cycle/update.html +++ b/period/templates/cycle/update.html @@ -12,4 +12,9 @@ + + +
+ +
{% endblock %} \ No newline at end of file