From b6a9bf5520c2bac03fb5113f686fd0d136df9967 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Fri, 1 Mar 2024 08:50:33 +0100 Subject: [PATCH 1/7] Implemented User-Invite Page --- app.py | 74 +++++++++++++++++++++++++++ templates/components/habit_lists.html | 7 ++- templates/users.html | 23 +++++++++ 3 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 templates/users.html diff --git a/app.py b/app.py index d3839a1..7b3e91e 100644 --- a/app.py +++ b/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) diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index 3ae3bb8..06dcb9d 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -77,12 +77,11 @@
- +
diff --git a/templates/users.html b/templates/users.html new file mode 100644 index 0000000..e306157 --- /dev/null +++ b/templates/users.html @@ -0,0 +1,23 @@ +{% extends 'layouts/main.html' %} + +{% block content %} + +

{{ habit_list.name }}: {{ title }}

+

Lade Nutzer per ihrer E-Mail-Adresse ein

+ +
+
+ + +
+ {{ errors.get('email', '') }} +
+
+ + + + + +
+ +{% endblock %} From 2dc3cbf047b245b379021fc60cfd538b80a9c1dc Mon Sep 17 00:00:00 2001 From: Verox001 Date: Fri, 1 Mar 2024 09:17:52 +0100 Subject: [PATCH 2/7] Implemented User Display on Habitlist --- app.py | 19 ++-- models/HabitList.py | 5 +- templates/components/habit_lists.html | 13 +-- templates/components/scripts.html | 144 +++++++++++++------------- 4 files changed, 92 insertions(+), 89 deletions(-) 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 From c2c38f55c49da74f472c4ead8be45c4e6bb13c60 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Fri, 1 Mar 2024 09:25:36 +0100 Subject: [PATCH 3/7] Remove plus icon from not primary users --- templates/components/habit_lists.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index d6892e8..892535c 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -66,6 +66,8 @@
+ {% if habit_list.get_users()[0].id == current_user.id %} + {% if habit_list.get_users()|length > 1 %}
{% for user in habit_list.get_users() %} @@ -75,15 +77,19 @@ {% endfor %}
+ {% endif %}
+ {% else %} +
+ {% endif %}
From 4bce1aab30ba3d3923224e0efdace0ba8e22b4bd Mon Sep 17 00:00:00 2001 From: janphilippweinsheimer Date: Fri, 1 Mar 2024 09:26:45 +0100 Subject: [PATCH 4/7] uniform design (card) --- templates/auth/login.html | 4 +-- templates/auth/signup.html | 55 +++++++++++++++++++++----------------- templates/habit-list.html | 6 ++--- templates/habit.html | 6 ++--- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/templates/auth/login.html b/templates/auth/login.html index 68edeca..8276503 100644 --- a/templates/auth/login.html +++ b/templates/auth/login.html @@ -1,8 +1,8 @@ {% extends 'layouts/main.html' %} {% block content %} -
-
Login
+
+

Login

diff --git a/templates/auth/signup.html b/templates/auth/signup.html index bbbf537..d3a727b 100644 --- a/templates/auth/signup.html +++ b/templates/auth/signup.html @@ -1,33 +1,38 @@ {% extends 'layouts/main.html' %} {% block content %} -
-

Registrieren

- -
- - -
- {{ errors.get('email', '') }} +
+
+

Registrieren

+ +
+ + +
+ {{ errors.get('email', '') }} +
-
-
- - -
- {{ errors.get('name', '') }} +
+ + +
+ {{ errors.get('name', '') }} +
-
-
- - -
- {{ errors.get('password', '') }} +
+ + +
+ {{ errors.get('password', '') }} +
-
-
- -
- +
+ +
+ +
{% endblock %} \ No newline at end of file diff --git a/templates/habit-list.html b/templates/habit-list.html index 3550013..ed0a590 100644 --- a/templates/habit-list.html +++ b/templates/habit-list.html @@ -1,8 +1,8 @@ {% extends 'layouts/main.html' %} {% block content %} - -

Habitliste erstellen📋

+
+

Habitliste erstellen📋

@@ -21,5 +21,5 @@
- +
{% endblock %} \ No newline at end of file diff --git a/templates/habit.html b/templates/habit.html index ecaffe7..0d116c1 100644 --- a/templates/habit.html +++ b/templates/habit.html @@ -1,8 +1,8 @@ {% extends 'layouts/main.html' %} {% block content %} - -

Habit erstellen📋

+
+

Habit erstellen📋

@@ -78,5 +78,5 @@ - +
{% endblock %} \ No newline at end of file From 0b927009b5eccbc639081414a51727846d86fe2e Mon Sep 17 00:00:00 2001 From: janphilippweinsheimer Date: Fri, 1 Mar 2024 10:30:41 +0100 Subject: [PATCH 5/7] uniform design (card) + names + deleted Home --- app.py | 7 +++++- templates/components/habit_lists.html | 6 ++--- templates/habit-list.html | 2 +- templates/habit.html | 2 +- templates/users.html | 32 ++++++++++++++------------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app.py b/app.py index bc5b2cd..fc1013b 100644 --- a/app.py +++ b/app.py @@ -135,10 +135,15 @@ def index(): for habit_list in habit_lists: habit_list.habits = sorted(habit_list.get_habits(), key=lambda habit: (not habit.checked, habit.slot)) + days = {"Monday": "Montag", "Tuesday": "Dienstag", "Wednesday": "Mittwoch", "Thursday": "Donnerstag", + "Friday": "Freitag", "Saturday": "Samstag", "Sunday": "Sonntag"} + + date = datetime.datetime.now().strftime("%d.%m.%Y %H:%M ") + days[datetime.datetime.now().strftime("%A")] + return render_template( 'index.html', title=name, - utc_dt=datetime.datetime.now().strftime("%d.%m.%Y %H:%M %A"), + utc_dt=date, habit_lists=habit_lists, heatmap_values=heatmap_values, errors={}, diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index 892535c..832e9ea 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -121,7 +121,7 @@
-
{{ habit.note }}
@@ -129,7 +129,7 @@
{% if not habit.streak == 0 %} - {{ habit.streak }} 🔥 + {{ habit.streak }}20 🔥 {% endif %}
@@ -140,7 +140,7 @@ - + diff --git a/templates/habit-list.html b/templates/habit-list.html index ed0a590..bd3c2c4 100644 --- a/templates/habit-list.html +++ b/templates/habit-list.html @@ -2,7 +2,7 @@ {% block content %}
-

Habitliste erstellen📋

+

Gewohnheitsliste erstellen📋

diff --git a/templates/habit.html b/templates/habit.html index 0d116c1..f1bc573 100644 --- a/templates/habit.html +++ b/templates/habit.html @@ -2,7 +2,7 @@ {% block content %}
-

Habit erstellen📋

+

Gewohnheit erstellen📋

diff --git a/templates/users.html b/templates/users.html index e306157..e17ee21 100644 --- a/templates/users.html +++ b/templates/users.html @@ -1,23 +1,25 @@ {% extends 'layouts/main.html' %} {% block content %} +