Implemented User Display on Habitlist

This commit is contained in:
Verox001 2024-03-01 09:17:52 +01:00
parent b6a9bf5520
commit 2dc3cbf047
4 changed files with 92 additions and 89 deletions

19
app.py
View File

@ -543,6 +543,16 @@ def add_user():
if user.id == current_user.id: if user.id == current_user.id:
errors['email'] = 'Du kannst dich nicht selbst hinzufügen.' 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: if errors:
return render_template( return render_template(
'users.html', 'users.html',
@ -557,14 +567,7 @@ def add_user():
habit_list = HabitList.get(int(habit_list_id)) habit_list = HabitList.get(int(habit_list_id))
habit_list.add_user(user) habit_list.add_user(user)
return render_template( return redirect(url_for('index', habit_list=habit_list.id))
'users.html',
title='Teilnehmer',
habit_list=habit_list,
users=habit_list.get_users(),
errors={},
email=email,
)
# Run the application # Run the application

View File

@ -53,15 +53,14 @@ class HabitList:
raw_users = get_users(self.id) raw_users = get_users(self.id)
users = [] users = []
for user in raw_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) users.append(user)
return users return users
# Adds a User by email to the HabitList # Adds a User by email to the HabitList
def add_user(self, email: str): def add_user(self, user: User):
user = User.get_by_email(email)
if user: if user:
add_user(self.id, user.id) add_user(self.id, user.id)
else: else:

View File

@ -66,17 +66,18 @@
<div class="row mb-3 align-items-center"> <div class="row mb-3 align-items-center">
<!-- Personen die zur Liste gehören --> <!-- Personen die zur Liste gehören -->
<div class="col-2"> <div class="col">
<div class="avatar-stack"> <div class="avatar-stack">
<img class="avatar" src="/images/avatar/1.jpg"/> {% for user in habit_list.get_users() %}
<img class="avatar" src="/images/avatar/2.jpg"/> {% if current_user.id != user.id %}
<img class="avatar" src="/images/avatar/4.jpg"/> <img class="avatar" src="/{{user.profile_image}}" data-toggle="tooltip" data-placement="top" title="{{user.name}}"/>
<img class="avatar" src="/images/avatar/5.jpg"/> {% endif %}
{% endfor %}
</div> </div>
</div> </div>
<!-- Knopf für das Hinzufügen einer Person zur gemeinsamen Liste --> <!-- Knopf für das Hinzufügen einer Person zur gemeinsamen Liste -->
<div class="col-1"> <div class="col">
<a href="/users?habit_list={{habit_list.id}}" style="width: 40px; height: 40px; min-height: 3em;"> <a href="/users?habit_list={{habit_list.id}}" style="width: 40px; height: 40px; min-height: 3em;">
<i class="bi bi-plus-circle"></i> <i class="bi bi-plus-circle"></i>

View File

@ -1,4 +1,3 @@
<script> <script>
function checkCompletionAndAnimate(habitId, percentage) { function checkCompletionAndAnimate(habitId, percentage) {
var progressBar = document.getElementById("progress-bar-" + habitId); var progressBar = document.getElementById("progress-bar-" + habitId);
@ -106,6 +105,7 @@
} }
}); });
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script> </script>