diff --git a/app.py b/app.py index 087d361..a28b27f 100644 --- a/app.py +++ b/app.py @@ -207,6 +207,10 @@ def habit_create(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' + # Check if unit is day and times is one + if unit == 'Tag' and times != 1: + errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.' + if errors: return render_template( 'habit.html', @@ -378,6 +382,9 @@ def edit_habit_change(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' + if unit == 'Tag' and times != 1: + errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.' + if errors: return render_template( "edit-habit.html", @@ -561,6 +568,24 @@ def delete_habit(): return {} +@app.route('/delete-list', methods=['POST']) +@login_required +def delete_list(): + list_id = request.get_json()["listId"] + + habit_list = HabitList.get(list_id) + + if habit_list is None: + return {"error": "List not found"} + + # Check if habit belongs to user + if current_user not in habit_list.get_users(): + return {"error": "List does not belong to user"} + + habit_list.delete() + return {} + + @app.route('/reorder', methods=['POST']) @login_required def reorder_habits(): @@ -660,4 +685,4 @@ def add_user(): # Run the application if __name__ == '__main__': - app.run(port=5000, debug=True) + app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index d9b811c..efb9bb9 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -190,7 +190,7 @@ def update_slot(id: int, slot: int): def update_habit(id: int, name: str, note: str, times: int, unit: int): now = datetime.now().isoformat() - query = (f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit}, updated_at = '{now}' " + query = (f"UPDATE habits SET name = '{name}', note = '{note}', times = {times}, unit = {unit}, updated_at = '{now}' " f"WHERE id = {id};") conn = con3() cursor = conn.cursor() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dc40e89 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pillow~=10.2.0 +flask~=3.0.0 +flask-login~=0.6.3 \ No newline at end of file diff --git a/templates/components/delete_list.html b/templates/components/delete_list.html new file mode 100644 index 0000000..b140c83 --- /dev/null +++ b/templates/components/delete_list.html @@ -0,0 +1,20 @@ + +
\ No newline at end of file diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index a111a4a..86b2653 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -15,7 +15,7 @@