Deletes are now functional for both User and Habit
Also changed get_habits from the Habit class to the User class
This commit is contained in:
parent
52ba6988fd
commit
0d80cdcf9b
2
app.py
2
app.py
@ -4,8 +4,8 @@ import hashlib
|
|||||||
from flask import Flask, render_template, redirect, url_for, request
|
from flask import Flask, render_template, redirect, url_for, request
|
||||||
from flask_login import login_required, LoginManager, login_user, logout_user, current_user
|
from flask_login import login_required, LoginManager, login_user, logout_user, current_user
|
||||||
|
|
||||||
from models.Habit import Habit
|
|
||||||
from models.User import User
|
from models.User import User
|
||||||
|
from models.Habit import Habit
|
||||||
from utils import anonymous_required
|
from utils import anonymous_required
|
||||||
|
|
||||||
# Create a new Flask instance
|
# Create a new Flask instance
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from db.SQLiteClient import create_habit, get_habits, get_habit
|
from db.SQLiteClient import create_habit, get_habit, delete_habit
|
||||||
|
|
||||||
|
|
||||||
# Unit wird als Integers wie folgt gemessen:
|
# Unit wird als Integers wie folgt gemessen:
|
||||||
# 0: Tag
|
# 0: Tag
|
||||||
@ -28,10 +29,5 @@ class Habit:
|
|||||||
return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all(user_id):
|
def delete(id: int):
|
||||||
raw_habits = get_habits(user_id)
|
delete_habit(id)
|
||||||
habits = []
|
|
||||||
for habit in raw_habits:
|
|
||||||
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6])
|
|
||||||
habits.append(habit)
|
|
||||||
return habits if habits else None
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from db.SQLiteClient import create_user, get_user, get_user_by_email
|
from db.SQLiteClient import create_user, get_user, get_user_by_email, get_habits, delete_user
|
||||||
|
from models.Habit import Habit
|
||||||
|
|
||||||
|
|
||||||
class User(UserMixin):
|
class User(UserMixin):
|
||||||
@ -23,3 +24,15 @@ class User(UserMixin):
|
|||||||
def get_by_email(email: str):
|
def get_by_email(email: str):
|
||||||
user = get_user_by_email(email)
|
user = get_user_by_email(email)
|
||||||
return User(user[0], user[1], user[2], user[3]) if user else None
|
return User(user[0], user[1], user[2], user[3]) if user else None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete(id: id):
|
||||||
|
delete_user(id)
|
||||||
|
|
||||||
|
def get_habits(self):
|
||||||
|
raw_habits = get_habits(self.id)
|
||||||
|
habits = []
|
||||||
|
for habit in raw_habits:
|
||||||
|
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6])
|
||||||
|
habits.append(habit)
|
||||||
|
return habits if habits else None
|
||||||
Loading…
x
Reference in New Issue
Block a user