From ece973ad28ae5f16da754a7952fd1db0e99d2cf2 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Thu, 7 Mar 2024 19:01:00 +0100 Subject: [PATCH] Fixed checked habit sorting --- app.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index cda5edb..988146a 100644 --- a/app.py +++ b/app.py @@ -142,7 +142,7 @@ def index(): # Sort habits by whether they have been checked today and then by slot for habit_list in habit_lists: - habit_list.habits = sorted(habit_list.get_habits(), key=lambda habit: (not habit.checked, habit.slot)) + habit_list.habits = sorted(habit_list.get_habits(), key=lambda habit: (habit.checked, habit.slot)) days = {"Monday": "Montag", "Tuesday": "Dienstag", "Wednesday": "Mittwoch", "Thursday": "Donnerstag", "Friday": "Freitag", "Saturday": "Samstag", "Sunday": "Sonntag"} @@ -795,6 +795,46 @@ def user_leave(): habit_list.remove_user(current_user.id) return redirect(url_for("index")) +@app.route('/accept-list', methods=['POST']) +@login_required +def accept_list(): + list_id = request.form.get('list_id') + habit_list = HabitList.get(int(list_id)) + + users = habit_list.get_users() + # Check if user is part of the list + found = False + for user in users: + if user.id == habit_list.id: + found = True + break + + if not found: + return redirect(url_for("index")) + + current_user.accept_List(list_id) + return {} + +@app.route('/deny-list', methods=['POST']) +@login_required +def deny_list(): + list_id = request.form.get('list_id') + habit_list = HabitList.get(int(list_id)) + + users = habit_list.get_users() + # Check if user is part of the list + found = False + for user in users: + if user.id == habit_list.id: + found = True + break + + if not found: + return redirect(url_for("index")) + + habit_list.remove_user(current_user.id) + return {} + # Run the application if __name__ == '__main__':