From 7745518950e2502bf12079f3083f1006922df4ad Mon Sep 17 00:00:00 2001 From: Verox001 Date: Fri, 2 Feb 2024 08:07:47 +0100 Subject: [PATCH 1/5] Fixed date checking --- models/Habit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/Habit.py b/models/Habit.py index 4b6c65e..6fc2b56 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -81,12 +81,12 @@ class Habit: count = 0 self.checked = False for tracking in self.get_habitTrackings(): - if tracking.created_at.day == datetime.today().day: + if tracking.created_at == datetime.today(): self.checked = True # day if self.unit == 0: - if tracking.created_at.day == datetime.today().day: + if tracking.created_at == datetime.today(): # self.checked = True count += 1 # week From b816ac1ef7a7b0e44e3ae494e3a81e115a22f511 Mon Sep 17 00:00:00 2001 From: Yapollon Date: Fri, 2 Feb 2024 08:30:34 +0100 Subject: [PATCH 2/5] fixed update slot Changing slots is now possible --- db/SQLiteClient.py | 24 ++++++++++++++---------- models/Habit.py | 11 +++++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index 514a7d6..4220d40 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -140,20 +140,22 @@ def get_slots(user_id: int): return slots -def update_habit(id: int, name: str, note: str, times: int, unit: int): - query = f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit} WHERE id = {id};" - conn = con3() - cursor = conn.cursor() - cursor.execute(query) - conn.close() - return cursor.lastrowid - - def update_slot(id: int, slot: int): query = f"UPDATE habits SET slot = {slot} WHERE id = {id};" conn = con3() cursor = conn.cursor() cursor.execute(query) + conn.commit() + conn.close() + return cursor.lastrowid + + +def update_habit(id: int, name: str, note: str, times: int, unit: int): + query = f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit} WHERE id = {id};" + conn = con3() + cursor = conn.cursor() + cursor.execute(query) + conn.commit() conn.close() return cursor.lastrowid @@ -210,4 +212,6 @@ def delete_habitTrackings(id: int): if __name__ == "__main__": - pass \ No newline at end of file + habits = get_habits(1) + for habit in habits: + print(habit[6]) diff --git a/models/Habit.py b/models/Habit.py index 4b6c65e..38208d0 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -23,22 +23,25 @@ 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 + def update(self, name: str=None, note: str=None, times: int=None, unit: int=None): update_habit(self.id, name, note, times, unit) if name is not None: @@ -50,10 +53,12 @@ class Habit: if unit is not None: self.unit = unit + # So sollte die Slots Liste aussehen damit es funktioniert #[(id, 1), (id, 2), (id, 3), (id, 4), (id, 5)] 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: @@ -62,7 +67,7 @@ class Habit: slots = slots[new_slot-1:self.slot-1] for slot in slots: update_slot(slot[0], slot[1]+1) - self.slot = new_slot + update_slot(self.id, new_slot) def delete(self): @@ -106,5 +111,3 @@ class Habit: count += 1 self.percentage = int(count / self.times * 100) - - From 79c8636ce11d1b3e26c413adbabb6d83c5474a11 Mon Sep 17 00:00:00 2001 From: Yapollon Date: Fri, 2 Feb 2024 08:32:45 +0100 Subject: [PATCH 3/5] cleanup --- app.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app.py b/app.py index b3398df..6c21201 100644 --- a/app.py +++ b/app.py @@ -211,16 +211,6 @@ def habit_create(): # Back to index return redirect(url_for('index')) - """return render_template( - 'habit.html', - title='Erstelle ein Habit', - name=name, - note=note, - times=times, - unit=unit, - errors=errors, - )""" - @app.route('/profile') @login_required From f8ee727705acd6181d796eea2c9d9586d218c263 Mon Sep 17 00:00:00 2001 From: Yapollon Date: Fri, 2 Feb 2024 08:34:02 +0100 Subject: [PATCH 4/5] cleanup 2 --- app.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/app.py b/app.py index 6c21201..295a8cc 100644 --- a/app.py +++ b/app.py @@ -290,28 +290,6 @@ def check_habit(): for tracking in trackings: if tracking.created_at.date() == datetime.date.today(): delete_tracking = tracking - """ - # day - if habit.unit == 0: - if tracking.created_at.date() == datetime.date.today(): - delete_tracking = tracking - break - # week - elif habit.unit == 1: - if tracking.created_at.date().isocalendar()[1] == datetime.date.today().isocalendar()[1]: - delete_tracking = tracking - break - # month - elif habit.unit == 2: - if tracking.created_at.date().month == datetime.date.today().month: - delete_tracking = tracking - break - # year - elif habit.unit == 3: - if tracking.created_at.date().year == datetime.date.today().year: - delete_tracking = tracking - break - """ if not delete_tracking: HabitTrackings.create(habit_id, 1) From 159feb38e49376fe954a5cc52e3c2a8ff210c0a5 Mon Sep 17 00:00:00 2001 From: nikolaswollenberg Date: Fri, 2 Feb 2024 08:56:04 +0100 Subject: [PATCH 5/5] Added dragndrop --- models/Habit.py | 3 + templates/index.html | 117 ++++++++++++++++++++++++++++++++++-- templates/layouts/main.html | 5 +- 3 files changed, 120 insertions(+), 5 deletions(-) diff --git a/models/Habit.py b/models/Habit.py index 4b6c65e..221934d 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -1,3 +1,4 @@ +import json from dataclasses import dataclass from datetime import datetime @@ -108,3 +109,5 @@ class Habit: self.percentage = int(count / self.times * 100) + 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..c61e2dc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -89,9 +89,12 @@ -
    +
      {% for habit in habits %} -
    • +
    • +
      + +
      @@ -150,7 +153,7 @@ var progressBar = document.getElementById("progress-bar-" + habitId); var habitBlock = document.getElementById("habit-" + habitId); - if (percentage >= 100) { + if (percentage == 100) { progressBar.style.backgroundColor = "green"; habitBlock.classList.add("animate-bounce"); setTimeout(function () { @@ -210,6 +213,112 @@ }); } - + + {% endblock %} \ No newline at end of file diff --git a/templates/layouts/main.html b/templates/layouts/main.html index dfbae44..051dbf3 100644 --- a/templates/layouts/main.html +++ b/templates/layouts/main.html @@ -5,10 +5,11 @@ {{ title }} - HabitTracker - + + @@ -53,6 +54,8 @@ + + \ No newline at end of file