diff --git a/models/Habit.py b/models/Habit.py index 45787e1..41a310d 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -1,3 +1,4 @@ +import json from dataclasses import dataclass from datetime import datetime @@ -23,22 +24,20 @@ class Habit: slot: int percentage: int = 0 - def __post_init__(self): self.fill_statistics() - @staticmethod def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1): slot = get_next_slot(user_id) id = create_habit(user_id, name, times, unit, slot, note) return Habit(id, user_id, name, note, times, unit, slot) - @staticmethod def get(id: int): habit = get_habit(id) habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None + return habit @@ -56,7 +55,6 @@ class Habit: def update_slot(self, new_slot: int): slots = get_slots(self.user_id) - print(slots) if new_slot > self.slot: slots = slots[self.slot:new_slot] for slot in slots: @@ -115,8 +113,5 @@ class Habit: self.percentage = int(count / self.times * 100) -# Test for update Slot - #user = User.get(1) - #habits = user.get_habits() - #print(habits[6]) - #habits[6].update_slot(3) \ No newline at end of file + def to_json(self): + return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4) diff --git a/templates/index.html b/templates/index.html index f00d2ea..8feb3eb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -92,6 +92,9 @@