Implemented User-Invite Page
This commit is contained in:
parent
7771c1eea2
commit
b6a9bf5520
74
app.py
74
app.py
@ -493,6 +493,80 @@ def reorder_habits():
|
||||
return {}
|
||||
|
||||
|
||||
@app.route('/users')
|
||||
@login_required
|
||||
def 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.html',
|
||||
title='Teilnehmer',
|
||||
habit_list=habit_list,
|
||||
users=users,
|
||||
errors={},
|
||||
)
|
||||
|
||||
@app.route('/users', methods=['POST'])
|
||||
@login_required
|
||||
def add_user():
|
||||
email = request.form.get('email')
|
||||
habit_list_id = request.form.get('habit_list_id')
|
||||
habit_list = HabitList.get(int(habit_list_id))
|
||||
|
||||
# Check for errors
|
||||
errors = {}
|
||||
if not email:
|
||||
errors['email'] = 'Die E-Mail Adresse ist erforderlich.'
|
||||
if not habit_list_id:
|
||||
errors['habit_list'] = 'Die Habitliste ist erforderlich.'
|
||||
|
||||
if errors:
|
||||
return render_template(
|
||||
'users.html',
|
||||
title='Teilnehmer',
|
||||
email=email,
|
||||
habit_list=habit_list,
|
||||
errors=errors,
|
||||
users=habit_list.get_users(),
|
||||
)
|
||||
|
||||
# Check if user exists
|
||||
user = User.get_by_email(email)
|
||||
if not user:
|
||||
errors['email'] = 'E-Mail Adresse nicht gefunden.'
|
||||
|
||||
if user.id == current_user.id:
|
||||
errors['email'] = 'Du kannst dich nicht selbst hinzufügen.'
|
||||
|
||||
if errors:
|
||||
return render_template(
|
||||
'users.html',
|
||||
title='Teilnehmer',
|
||||
email=email,
|
||||
habit_list=habit_list,
|
||||
errors=errors,
|
||||
users=habit_list.get_users(),
|
||||
)
|
||||
|
||||
# Add user to habit list
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
# Run the application
|
||||
if __name__ == '__main__':
|
||||
app.run(port=5000, debug=True)
|
||||
|
||||
@ -77,12 +77,11 @@
|
||||
|
||||
<!-- Knopf für das Hinzufügen einer Person zur gemeinsamen Liste -->
|
||||
<div class="col-1">
|
||||
<button type="button" class="btn"
|
||||
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"></i>
|
||||
<i class="bi bi-plus-circle"></i>
|
||||
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-6"></div>
|
||||
|
||||
23
templates/users.html
Normal file
23
templates/users.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends 'layouts/main.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{{ habit_list.name }}: {{ title }}</h1>
|
||||
<p>Lade Nutzer per ihrer E-Mail-Adresse ein</p>
|
||||
|
||||
<form action="/users" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">E-Mail</label>
|
||||
<input type="text" placeholder="beispiel@cimeyclust.com" class="form-control {% if errors.get('email') %} is-invalid {% endif %}" id="email" name="email" value="{{email}}">
|
||||
<div class="invalid-feedback">
|
||||
{{ errors.get('email', '') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input hidden="hidden" name="habit_list_id" value="{{ habit_list.id }}">
|
||||
|
||||
<!-- submit button -->
|
||||
<button type="submit" class="btn btn-primary">Einladen</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user