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 }} -