Optimized habit tracking

This commit is contained in:
Verox001 2024-01-26 11:17:09 +01:00
parent c19ea3bace
commit 428e2498dd

28
app.py
View File

@ -126,9 +126,8 @@ def index():
habits = [] habits = []
name = "Bitte melde dich an." name = "Bitte melde dich an."
# Add checked attribute to habits (if they have been checked today) # old code
for habit in habits: """trackings = habit.get_habitTrackings()
trackings = habit.get_habitTrackings()
for tracking in trackings: for tracking in trackings:
# day # day
if habit.unit == 0: if habit.unit == 0:
@ -151,6 +150,16 @@ def index():
habit.checked = True habit.checked = True
break break
else:
habit.checked = False"""
# Add checked attribute to habits (if they have been checked today)
for habit in habits:
trackings = habit.get_habitTrackings()
for tracking in trackings:
if tracking.created_at.date() == datetime.date.today():
habit.checked = True
break
else: else:
habit.checked = False habit.checked = False
@ -324,7 +333,7 @@ def check_habit():
trackings = habit.get_habitTrackings() trackings = habit.get_habitTrackings()
# Check if habit has been tracked today # Check if habit has been tracked today
delete_tracking = None """delete_tracking = None
for tracking in trackings: for tracking in trackings:
# day # day
if habit.unit == 0: if habit.unit == 0:
@ -347,6 +356,17 @@ def check_habit():
delete_tracking = tracking delete_tracking = tracking
break break
if not delete_tracking:
HabitTrackings.create(habit_id, 1)
else:
delete_tracking.delete()"""
delete_tracking = None
for tracking in trackings:
if tracking.created_at.date() == datetime.date.today():
delete_tracking = tracking
break
if not delete_tracking: if not delete_tracking:
HabitTrackings.create(habit_id, 1) HabitTrackings.create(habit_id, 1)
else: else: