diff --git a/app.py b/app.py index 69489ef..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"} @@ -297,6 +297,7 @@ def habit_list_create(): @app.route('/profile') @login_required def profile(): + print(current_user.name, current_user.email) return render_template( "profile.html", name=current_user.name, @@ -794,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__': diff --git a/models/HabitList.py b/models/HabitList.py index 0770075..b04f07c 100644 --- a/models/HabitList.py +++ b/models/HabitList.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from models.Habit import Habit from models.User import User from db.SQLiteClient import (create_habitList, get_habitList, get_habits, get_users, add_user, remove_user, - update_habitList, delete_habitList, accept_List) + update_habitList, delete_habitList) @dataclass @@ -66,9 +66,6 @@ class HabitList: else: return None - def accept_List(self, user:User): - accept_List(self.id, user.id) - # Removes a User from the HabitList def remove_user(self, user_id): remove_user(self.id, user_id) diff --git a/models/User.py b/models/User.py index 22a2e3d..8df5cfb 100644 --- a/models/User.py +++ b/models/User.py @@ -2,7 +2,7 @@ from datetime import datetime from flask_login import UserMixin from db.SQLiteClient import (create_user, get_user, get_user_by_email, update_user, delete_user, - get_habitLists, get_heatmap_value) + get_habitLists, get_heatmap_value, accept_List) class User(UserMixin): @@ -75,4 +75,7 @@ class User(UserMixin): heatmap.append(value) heatmap.reverse() day = 27-weekday - return heatmap, day \ No newline at end of file + return heatmap, day + + def accept_List(self, HabitList_id): + accept_List(self.id, HabitList_id) diff --git a/static/script/script-profile.js b/static/script/script-profile.js index 42c58c3..153f6dd 100644 --- a/static/script/script-profile.js +++ b/static/script/script-profile.js @@ -35,9 +35,9 @@ document.addEventListener("DOMContentLoaded", function() { // Add event listener to edit button to open modal editButton.addEventListener("click", function() { editModal.show(); - document.getElementById("newName").value = "{{ name }}"; - document.getElementById("newEmail").value = "{{ email }}"; - document.getElementById("password").value = ""; + // document.getElementById("newName").value = "{{ name }}"; + // document.getElementById("newEmail").value = "{{ email }}"; + // document.getElementById("password").value = ""; }); // Add event listener to save changes button to submit form diff --git a/templates/profile.html b/templates/profile.html index 66a9de7..aee799f 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -77,12 +77,12 @@
- +
- +
@@ -102,4 +102,5 @@ + {% endblock %} \ No newline at end of file