From 153f55f7b06328af969906517c48c7ccf7238dbc Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Fri, 29 Apr 2022 22:38:54 -0400 Subject: [PATCH] Make it pretty and update the current cycle calculation --- period/cycles.py | 12 +++++++++ period/templates/base.html | 2 +- period/templates/cycle/index.html | 44 +++++++++++++------------------ 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/period/cycles.py b/period/cycles.py index be14b24..3b0f55b 100644 --- a/period/cycles.py +++ b/period/cycles.py @@ -15,6 +15,18 @@ bp = Blueprint('cycles', __name__) @bp.route('/') def index(): db = get_db() + current_cycle = db.execute('SELECT * from cycle ORDER BY id DESC LIMIT 1').fetchone() + print(current_cycle['start_time']) + start_time = pendulum.parse(current_cycle['start_time']) + if current_cycle['end_time'] is None: + cycle_length = (pendulum.now() - start_time).days + + db.execute( + 'UPDATE cycle SET cycle_length = ?' + ' WHERE id = ?', + (cycle_length, current_cycle['id']) + ) + cycles = db.execute( 'SELECT id, start_time, end_time, cycle_length' ' FROM cycle ORDER BY start_time DESC' diff --git a/period/templates/base.html b/period/templates/base.html index c925004..9b592f1 100644 --- a/period/templates/base.html +++ b/period/templates/base.html @@ -15,7 +15,7 @@ margin: 30px 0; } .table-wrapper { - min-width: 1000px; + /* min-width: 1000px; */ background: #fff; padding: 20px 25px; border-radius: 3px; diff --git a/period/templates/cycle/index.html b/period/templates/cycle/index.html index 9602d32..554dde2 100644 --- a/period/templates/cycle/index.html +++ b/period/templates/cycle/index.html @@ -8,38 +8,32 @@
-
- {% block header %} -

{% block title %}Cycles{% endblock %}

- {% endblock %} -
- {% for cycle in cycles %} - -
-
-
-
Started: {{ cycle['start_time'] }}
- Ended: {{ cycle['end_time'] }}
+
+
+
+ {% if cycle['cycle_length'] %} + {% if loop.first %} + Day {{ cycle['cycle_length'] }} + {% else %} + {{ cycle['cycle_length'] }} days. + {% endif %} + {% else %} + {% endif %}
+

Started: {{ cycle['start_time'][:10] }} +
+ {% if not loop.first %} + Ended: {{ cycle['end_time'][:10] }} + {% endif %} +

+ Edit +
-
-

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

- Edit - {{ cycle['id'] }} -
{% if not loop.last %} -
{% endif %} - {% endfor %} -