edit users
This commit is contained in:
parent
817ef7f683
commit
20f9800203
61
app.py
61
app.py
@ -652,6 +652,67 @@ def users():
|
|||||||
errors={},
|
errors={},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.route('/users-edit')
|
||||||
|
@login_required
|
||||||
|
def edit_users():
|
||||||
|
habit_list_id = request.args.get('habit_list', current_user.get_habitLists()[0].id)
|
||||||
|
habit_list = HabitList.get(int(habit_list_id))
|
||||||
|
users = habit_list.get_users()
|
||||||
|
|
||||||
|
# Remove the current user from the list
|
||||||
|
users = [user for user in users if user.id != current_user.id]
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'users-edit.html',
|
||||||
|
title='Teilnehmer bearbeiten',
|
||||||
|
habit_list=habit_list,
|
||||||
|
users=users,
|
||||||
|
errors={},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/user-delete', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def delete_user_from_list():
|
||||||
|
habit_list_id = request.form.get('habit_list_id')
|
||||||
|
habit_list = HabitList.get(int(habit_list_id))
|
||||||
|
|
||||||
|
habit_user_id = request.form.get('habit_user_id')
|
||||||
|
habit_user = User.get(int(habit_user_id))
|
||||||
|
|
||||||
|
users = habit_list.get_users()
|
||||||
|
|
||||||
|
# Remove the current user from the list
|
||||||
|
users = [user for user in users if user.id != current_user.id]
|
||||||
|
|
||||||
|
# Check for errors
|
||||||
|
errors = {}
|
||||||
|
if not habit_list_id:
|
||||||
|
errors['habit_list'] = 'Die Habitliste ist erforderlich.'
|
||||||
|
if not habit_list_id:
|
||||||
|
errors['habit_user'] = 'Ein User ist erforderlich.'
|
||||||
|
|
||||||
|
if errors:
|
||||||
|
return render_template(
|
||||||
|
'users-edit.html',
|
||||||
|
title='Teilnehmer bearbeiten',
|
||||||
|
habit_list=habit_list,
|
||||||
|
users=users,
|
||||||
|
errors={},
|
||||||
|
)
|
||||||
|
|
||||||
|
# delete user from habit list
|
||||||
|
id = int(habit_user_id)
|
||||||
|
habit_list.delete(id)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'users-edit.html',
|
||||||
|
title='Teilnehmer bearbeiten',
|
||||||
|
habit_list=habit_list,
|
||||||
|
users=users,
|
||||||
|
errors={},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/users', methods=['POST'])
|
@app.route('/users', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@ -333,7 +333,7 @@ def add_user(list_id: int, user_id: int):
|
|||||||
|
|
||||||
|
|
||||||
def remove_user(list_id: int, user_id: int):
|
def remove_user(list_id: int, user_id: int):
|
||||||
query = f"DELETE FROM habit_lists WHERE user_id = {user_id} AND list_id = {list_id};"
|
query = f"DELETE FROM habit_users WHERE user_id = {user_id} AND list_id = {list_id};"
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|||||||
@ -65,14 +65,14 @@
|
|||||||
id="simple-tabpanel-{{habit_list.id}}" role="tabpanel" aria-labelledby="simple-tab-{{habit_list.id}}">
|
id="simple-tabpanel-{{habit_list.id}}" role="tabpanel" aria-labelledby="simple-tab-{{habit_list.id}}">
|
||||||
|
|
||||||
<!-- Beschreibung und Löschen von der Liste -->
|
<!-- Beschreibung und Löschen von der Liste -->
|
||||||
<div class="row mb-3">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{ habit_list.description }}
|
{{ habit_list.description }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<button type="button" class="btn btn-xs me-3" data-bs-toggle="modal"
|
<button type="button" class="btn btn-xs me-3" data-bs-toggle="modal"
|
||||||
data-bs-target="#listenModal" style="width: 40px; height: 40px"
|
data-bs-target="#listenModal"
|
||||||
onclick="{
|
onclick="{
|
||||||
localStorage.setItem('selectedListId', {{ habit_list.id }});
|
localStorage.setItem('selectedListId', {{ habit_list.id }});
|
||||||
}">
|
}">
|
||||||
@ -99,18 +99,27 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Knopf für das Hinzufügen einer Person zur gemeinsamen Liste -->
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<a href="/users?habit_list={{habit_list.id}}" style="width: 40px; height: 40px; min-height: 3em;"
|
<!-- Knopf für das Hinzufügen einer Person zur gemeinsamen Liste -->
|
||||||
|
<a class="me-5" href="/users?habit_list={{habit_list.id}}" style="width: 40px; height: 40px; min-height: 3em;"
|
||||||
data-toggle="tooltip" data-placement="top" title="Benutzer einladen">
|
data-toggle="tooltip" data-placement="top" title="Benutzer einladen">
|
||||||
<i class="bi bi-person-fill-add" style="font-size: 24px;"></i>
|
<i class="bi bi-person-fill-add" style="font-size: 24px;"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<!-- Knopf für das Bearbeiten von Personen zur gemeinsamen Liste -->
|
||||||
|
{% if habit_list.get_users()|length > 1 %}
|
||||||
|
<a href="/users-edit?habit_list={{habit_list.id}}" style="width: 40px; height: 40px; min-height: 3em;"
|
||||||
|
data-toggle="tooltip" data-placement="top" title="Benutzer bearbeiten">
|
||||||
|
<i class="bi bi-pencil"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="col"></div>
|
<div class="col"></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="col-6"></div>
|
<div class="col-4"></div>
|
||||||
|
|
||||||
|
|
||||||
<!-- neue Gewohnheiten erstellen -->
|
<!-- neue Gewohnheiten erstellen -->
|
||||||
<a class="col-3 btn btn-primary" role="button" href="/habit?list={{ habit_list.id }}">
|
<a class="col-3 btn btn-primary" role="button" href="/habit?list={{ habit_list.id }}">
|
||||||
|
|||||||
37
templates/users-edit.html
Normal file
37
templates/users-edit.html
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{% extends 'index.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="card bg-light p-5 mt-5">
|
||||||
|
<h1 class="mb-5">
|
||||||
|
{{ title }}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
|
||||||
|
{% for user in users %}
|
||||||
|
<form action="/user-delete" class="row" method="POST">
|
||||||
|
<div class="col">
|
||||||
|
<img src="{{ user.profile_image }}" class="avatar"/>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{{ user.name }}
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
{{ user.email }}
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<label>
|
||||||
|
<input hidden="hidden" name="habit_list_id" value="{{ habit_list.id }}">
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input hidden="hidden" name="habit_user_id" value="{{ user.id }}">
|
||||||
|
</label>
|
||||||
|
<button type="submit" class="btn btn-primary btn-danger">
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user