Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
c710fe7a78
1
app.py
1
app.py
@ -320,7 +320,6 @@ def delete_habit():
|
||||
return {"error": "Habit does not belong to user"}
|
||||
|
||||
habit.delete()
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
@ -43,10 +43,11 @@ def get_user_by_email(email: str):
|
||||
|
||||
|
||||
def update_user(id: int, name: str, email: str, password: str = None):
|
||||
now = datetime.now().isoformat()
|
||||
if password:
|
||||
query = f"UPDATE users SET name = '{name}', email = '{email}', password = '{password}' WHERE id = {id};"
|
||||
query = f"UPDATE users SET name = '{name}', email = '{email}', password = '{password}', updated_at = {now} WHERE id = {id};"
|
||||
else:
|
||||
query = f"UPDATE users SET name = '{name}', email = '{email}' WHERE id = {id};"
|
||||
query = f"UPDATE users SET name = '{name}', email = '{email}', updated_at = {now} WHERE id = {id};"
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
@ -104,7 +105,8 @@ def get_heatmap_value(user_id: int, days: int):
|
||||
date = (datetime.now() - timedelta(days=days)).date()
|
||||
print(date)
|
||||
query = f"SELECT id FROM habits WHERE user_id = {user_id};"
|
||||
query2 = f"SELECT habits.id FROM habits, habit_trackings WHERE habits.user_id = {user_id} AND habits.created_at LIKE '{date}%' AND habit_trackings.habit_id = habits.id;"
|
||||
query2 = (f"SELECT habits.id FROM habits, habit_trackings WHERE habits.user_id = {user_id} "
|
||||
f"AND habits.created_at LIKE '{date}%' AND habit_trackings.habit_id = habits.id;")
|
||||
print(query2)
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
@ -141,7 +143,8 @@ def get_slots(user_id: int):
|
||||
|
||||
|
||||
def update_slot(id: int, slot: int):
|
||||
query = f"UPDATE habits SET slot = {slot} WHERE id = {id};"
|
||||
now = datetime.now().isoformat()
|
||||
query = f"UPDATE habits SET slot = {slot}, updated_at = {now} WHERE id = {id};"
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
@ -151,7 +154,8 @@ def update_slot(id: int, slot: int):
|
||||
|
||||
|
||||
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};"
|
||||
now = datetime.now().isoformat()
|
||||
query = f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit}, updated_at = {now} WHERE id = {id};"
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
|
||||
@ -40,6 +40,7 @@ class Habit:
|
||||
|
||||
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:
|
||||
@ -51,8 +52,7 @@ 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)
|
||||
if new_slot > self.slot:
|
||||
@ -63,10 +63,14 @@ 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):
|
||||
slots = get_slots(self.user_id)[self.slot+1:]
|
||||
print(slots)
|
||||
for slot in slots:
|
||||
update_slot(slot[0], slot[1] - 1)
|
||||
delete_habit(self.id)
|
||||
|
||||
|
||||
@ -82,12 +86,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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user