From 32cec2e7313e7d716d455d9b4d4f8c89f489ad99 Mon Sep 17 00:00:00 2001 From: janphilippweinsheimer Date: Thu, 7 Mar 2024 14:20:45 +0100 Subject: [PATCH] times errors and cards --- app.py | 17 ++++- templates/components/habit_lists.html | 19 ++++-- templates/edit-habit.html | 93 ++++++++++++++------------- 3 files changed, 76 insertions(+), 53 deletions(-) diff --git a/app.py b/app.py index 75dd599..5b5798d 100644 --- a/app.py +++ b/app.py @@ -208,9 +208,15 @@ def habit_create(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' - # Check if unit is day and times is one + # Check if times is possible to achieve if unit == 'Tag' and times != 1: errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.' + if unit == 'Woche' and times > 7: + errors['times'] = 'Die Anzahl darf höchstens 7 sein, wenn das Habit wöchentlich ist.' + if unit == 'Monat' and times > 31: + errors['times'] = 'Die Anzahl darf höchstens 31 sein, wenn das Habit monatlich ist.' + if unit == 'Jahr' and times > 365: + errors['times'] = 'Die Anzahl darf höchstens 365 sein, wenn das Habit jährlich ist.' if errors: return render_template( @@ -384,8 +390,15 @@ def edit_habit_change(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' + # Check if times is possible to achieve if unit == 'Tag' and times != 1: errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.' + if unit == 'Woche' and times > 7: + errors['times'] = 'Die Anzahl darf höchstens 7 sein, wenn das Habit wöchentlich ist.' + if unit == 'Monat' and times > 31: + errors['times'] = 'Die Anzahl darf höchstens 31 sein, wenn das Habit monatlich ist.' + if unit == 'Jahr' and times > 365: + errors['times'] = 'Die Anzahl darf höchstens 365 sein, wenn das Habit jährlich ist.' if errors: return render_template( @@ -396,7 +409,7 @@ def edit_habit_change(): note=habit.note, times=habit.times, unit=units[habit.unit], - errors={} + errors=errors ) # Map unit to integer diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index 56a4017..867d2df 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -70,13 +70,13 @@ {{ habit_list.description }} -
+
@@ -91,7 +91,8 @@
{% for user in habit_list.get_users() %} {% if current_user.id != user.id %} - + {% endif %} {% endfor %}
@@ -100,7 +101,8 @@ -
+
{% if not habit.streak == 0 %} {{ habit.streak }} 🔥 {% endif %} @@ -160,8 +163,9 @@ - + @@ -196,4 +200,5 @@ function setSelectedListId(listId) { selectedlistId = listId; } + diff --git a/templates/edit-habit.html b/templates/edit-habit.html index ccf95ac..d258e75 100644 --- a/templates/edit-habit.html +++ b/templates/edit-habit.html @@ -1,42 +1,45 @@ {% extends 'index.html' %} {% block content %} +
+

Habit Bearbeiten📋

-

Habit Bearbeiten📋

- -
-
- - -
- {{ errors.get('name', '') }} -
-
-
- - -
- {{ errors.get('note', '') }} -
-
- -
-
- - + +
+ +
- {{ errors.get('times', '') }} + {{ errors.get('name', '') }}
-
- - - -
- {{ errors.get('unit', '') }} + + +
+ {{ errors.get('unit', '') }} +
-
- -
- {{ errors.get('list_query', '') }} -
- - - + + + +
{% endblock %} \ No newline at end of file