diff --git a/app.py b/app.py index 7b3e91e..bc5b2cd 100644 --- a/app.py +++ b/app.py @@ -543,6 +543,16 @@ def add_user(): if user.id == current_user.id: errors['email'] = 'Du kannst dich nicht selbst hinzufügen.' + # Check if user is already in the habit list + already = False + for u in habit_list.get_users(): + if u.id == user.id: + already = True + break + + if already: + errors['email'] = 'Teilnehmer ist bereits in der Liste.' + if errors: return render_template( 'users.html', @@ -557,14 +567,7 @@ def add_user(): habit_list = HabitList.get(int(habit_list_id)) habit_list.add_user(user) - return render_template( - 'users.html', - title='Teilnehmer', - habit_list=habit_list, - users=habit_list.get_users(), - errors={}, - email=email, - ) + return redirect(url_for('index', habit_list=habit_list.id)) # Run the application diff --git a/models/HabitList.py b/models/HabitList.py index e20ac25..1346390 100644 --- a/models/HabitList.py +++ b/models/HabitList.py @@ -53,15 +53,14 @@ class HabitList: raw_users = get_users(self.id) users = [] for user in raw_users: - user = User(user[0], user[1], user[2], user[3]) + user = User(user[0], user[1], user[2], user[3], user[4]) users.append(user) return users # Adds a User by email to the HabitList - def add_user(self, email: str): - user = User.get_by_email(email) + def add_user(self, user: User): if user: add_user(self.id, user.id) else: diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index 06dcb9d..d6892e8 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -66,17 +66,18 @@
-
+
- - - - + {% for user in habit_list.get_users() %} + {% if current_user.id != user.id %} + + {% endif %} + {% endfor %}
-
+
diff --git a/templates/components/scripts.html b/templates/components/scripts.html index 161588d..c05ac07 100644 --- a/templates/components/scripts.html +++ b/templates/components/scripts.html @@ -1,81 +1,80 @@ - \ No newline at end of file