From f7967c2dfd8ec74783d55a3ed5e0675db3dbd886 Mon Sep 17 00:00:00 2001 From: nikolaswollenberg Date: Fri, 1 Mar 2024 09:25:27 +0100 Subject: [PATCH 01/14] many --- app.py | 100 +++++++++++++++++++++++++++++++++----- templates/edit-habit.html | 79 +++++++++++++++++++++++++++++- 2 files changed, 166 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index d3839a1..cbce558 100644 --- a/app.py +++ b/app.py @@ -303,26 +303,104 @@ def profile_change(): @app.route('/edit-habit') @login_required def edit_habit(): - habit_id = request.args.get("habit") - #habit_id = request.get_json()["editHabitId"] - + habit_id = int(request.args.get("habit")) habit = Habit.get(habit_id) + + + units = ["Tag", "Woche", "Monat", "Jahr"] + return render_template( "edit-habit.html", - title=habit.name + title=habit.name, + habit=habit.id, + name=habit.name, + note=habit.note, + times=habit.times, + unit=units[habit.unit], + errors={} ) -''' + @app.route('/edit-habit', methods=['POST']) @login_required def edit_habit_change(): - #habit_id = request.get_json()["habitId"] - #habit = Habit.get(habit_id) - return render_template( - "edit-habit.html" - ) -''' + units = ["Tag", "Woche", "Monat", "Jahr"] + name = request.form.get('name') + note = request.form.get('note') + times = request.form.get('times') + unit = request.form.get('unit') + list_id = request.form.get('habit') + + habit = Habit.get(list_id) + + # Check for errors + errors = {} + if not name: + errors['name'] = 'Der Name ist erforderlich.' + if not times: + errors['times'] = 'Die Anzahl ist erforderlich.' + if not note: + note = '' + if not unit: + errors['unit'] = 'Die Einheit ist erforderlich.' + if not list_id: + errors['habit'] = 'Das Habit ist erforderlich.' + + # Check if times is an integer + try: + print(times) + times = int(times) + + + # Check that times is greater than 0 + if times <= 0: + errors['times'] = 'Die Anzahl muss größer als 0 sein.' + except ValueError: + errors['times'] = 'Die Anzahl muss eine Zahl sein.' + + # Check that unit is valid + if unit not in ['Tag', 'Woche', 'Monat', 'Jahr']: + errors['unit'] = 'Die Einheit ist ungültig.' + + # check if list_id is an int + try: + list_id = int(list_id) + except ValueError: + errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' + + if errors: + return render_template( + "edit-habit.html", + title=habit.name, + habit=habit.id, + name=habit.name, + note=habit.note, + times=habit.times, + unit=units[habit.unit], + errors={} + ) + + # Map unit to integer + if unit == 'Tag': + unit = 0 + elif unit == 'Woche': + unit = 1 + elif unit == 'Monat': + unit = 2 + elif unit == 'Jahr': + unit = 3 + else: + unit = 1 + + # Save habit to database + print(name, note, times, unit) + habit.name, habit.note, habit.times, habit.unit = name, note, times, unit + + habit.update() + # Back to index + return redirect(url_for('index')) + @app.route('/check_password', methods=['POST']) @login_required def check_password(): diff --git a/templates/edit-habit.html b/templates/edit-habit.html index fbe5b9e..ccf95ac 100644 --- a/templates/edit-habit.html +++ b/templates/edit-habit.html @@ -2,6 +2,81 @@ {% block content %} -test -{{ title }} +

Habit Bearbeiten📋

+ +
+
+ + +
+ {{ errors.get('name', '') }} +
+
+
+ + +
+ {{ errors.get('note', '') }} +
+
+ +
+
+ + +
+ {{ errors.get('times', '') }} +
+
+
+ + + +
+ {{ errors.get('unit', '') }} +
+
+
+ + +
+ {{ errors.get('list_query', '') }} +
+ + +
+ {% endblock %} \ No newline at end of file From 2a249a32e516c3da842c3cc89682eca38d1924c2 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 09:47:23 +0100 Subject: [PATCH 02/14] Fixed user None Check --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 13f51fe..240bd31 100644 --- a/app.py +++ b/app.py @@ -549,7 +549,7 @@ def add_user(): if not user: errors['email'] = 'E-Mail Adresse nicht gefunden.' - if user.id == current_user.id: + if user and user.id == current_user.id: errors['email'] = 'Du kannst dich nicht selbst hinzufügen.' # Check if user is already in the habit list From 53a884d23e33dff0e8f4884aa886022af43550e0 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 09:49:38 +0100 Subject: [PATCH 03/14] Fixed user None Check --- app.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 240bd31..c863a20 100644 --- a/app.py +++ b/app.py @@ -554,10 +554,11 @@ def add_user(): # 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 user: + 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.' From 6282c374f7cac26951009ce6b22b86769f750384 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 09:59:09 +0100 Subject: [PATCH 04/14] Fixed habit times check --- app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app.py b/app.py index 087d361..e4a9fa7 100644 --- a/app.py +++ b/app.py @@ -207,6 +207,10 @@ def habit_create(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' + # Check if unit is day and times is one + if unit == 'Tag' and times == 1: + errors['times'] = 'Die Anzahl muss größer als 1 sein, wenn das Habit täglich ist.' + if errors: return render_template( 'habit.html', @@ -378,6 +382,9 @@ def edit_habit_change(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' + if unit == 'Tag' and times == 1: + errors['times'] = 'Die Anzahl muss größer als 1 sein, wenn das Habit täglich ist.' + if errors: return render_template( "edit-habit.html", From 45f39745147faa50366a2f1eec54ae91a7f36600 Mon Sep 17 00:00:00 2001 From: janphilippweinsheimer Date: Tue, 5 Mar 2024 10:05:38 +0100 Subject: [PATCH 05/14] fixed yassins wrongdoing --- db/SQLiteClient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index d9b811c..efb9bb9 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -190,7 +190,7 @@ def update_slot(id: int, slot: int): def update_habit(id: int, name: str, note: str, times: int, unit: int): now = datetime.now().isoformat() - query = (f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit}, updated_at = '{now}' " + query = (f"UPDATE habits SET name = '{name}', note = '{note}', times = {times}, unit = {unit}, updated_at = '{now}' " f"WHERE id = {id};") conn = con3() cursor = conn.cursor() From c258dec2bd9f71d2eb356cbcc942c3638774a8a3 Mon Sep 17 00:00:00 2001 From: nikolaswollenberg Date: Tue, 5 Mar 2024 10:13:02 +0100 Subject: [PATCH 06/14] Spline Integration --- templates/index.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/index.html b/templates/index.html index 3729e63..4f66f25 100644 --- a/templates/index.html +++ b/templates/index.html @@ -47,6 +47,11 @@ {% include 'components/delete_button.html' %} {% endif %} + {% if not current_user.is_authenticated %} + + + {% endif %} + {% include 'components/scripts.html' %} From 8814a6a834a6215ca4842cc4c19004e0492e8e03 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 10:13:50 +0100 Subject: [PATCH 07/14] Added requirements.txt --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fc4309f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pillow~=10.2.0 +flask~=3.0.0 \ No newline at end of file From 7aec15c4cd0cdce216446870ce592e0ccf206420 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 10:33:28 +0100 Subject: [PATCH 08/14] Updated requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fc4309f..dc40e89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pillow~=10.2.0 -flask~=3.0.0 \ No newline at end of file +flask~=3.0.0 +flask-login~=0.6.3 \ No newline at end of file From 295f02509c2e00110a062a84f46cb336db13e3ef Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 10:37:18 +0100 Subject: [PATCH 09/14] Started app at 0.0.0.0 host --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index e4a9fa7..b92f71e 100644 --- a/app.py +++ b/app.py @@ -667,4 +667,4 @@ def add_user(): # Run the application if __name__ == '__main__': - app.run(port=5000, debug=True) + app.run(host="0.0.0.0", port=5000, debug=True) From 51742411ca10aa74a12781410ac9dd38579b3cd3 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 10:49:29 +0100 Subject: [PATCH 10/14] Fixed day count --- app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index b92f71e..dd72258 100644 --- a/app.py +++ b/app.py @@ -208,8 +208,8 @@ def habit_create(): errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' # Check if unit is day and times is one - if unit == 'Tag' and times == 1: - errors['times'] = 'Die Anzahl muss größer als 1 sein, wenn das Habit täglich ist.' + if unit == 'Tag' and times != 1: + errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.' if errors: return render_template( @@ -382,8 +382,8 @@ def edit_habit_change(): except ValueError: errors['list_query'] = 'Die Anzahl muss eine Zahl sein.' - if unit == 'Tag' and times == 1: - errors['times'] = 'Die Anzahl muss größer als 1 sein, wenn das Habit täglich ist.' + if unit == 'Tag' and times != 1: + errors['times'] = 'Die Anzahl muss 1 sein, wenn das Habit täglich ist.' if errors: return render_template( From 785edd1f88a693382c0de1fe6903ea7b192b4de8 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 5 Mar 2024 10:54:26 +0100 Subject: [PATCH 11/14] Fixed SQL operational error --- db/SQLiteClient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index d9b811c..efb9bb9 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -190,7 +190,7 @@ def update_slot(id: int, slot: int): def update_habit(id: int, name: str, note: str, times: int, unit: int): now = datetime.now().isoformat() - query = (f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit}, updated_at = '{now}' " + query = (f"UPDATE habits SET name = '{name}', note = '{note}', times = {times}, unit = {unit}, updated_at = '{now}' " f"WHERE id = {id};") conn = con3() cursor = conn.cursor() From 424a423f7c2786b07fd418a9f3a4f12b0fdb4eea Mon Sep 17 00:00:00 2001 From: janphilippweinsheimer Date: Tue, 5 Mar 2024 11:15:43 +0100 Subject: [PATCH 12/14] delete list --- app.py | 18 ++++++++++++++++++ templates/components/delete_list.html | 20 ++++++++++++++++++++ templates/components/habit_lists.html | 24 ++++++++++++++++++++++-- templates/components/scripts.html | 22 ++++++++++++++++++++++ templates/index.html | 4 ++++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 templates/components/delete_list.html diff --git a/app.py b/app.py index dd72258..a28b27f 100644 --- a/app.py +++ b/app.py @@ -568,6 +568,24 @@ def delete_habit(): return {} +@app.route('/delete-list', methods=['POST']) +@login_required +def delete_list(): + list_id = request.get_json()["listId"] + + habit_list = HabitList.get(list_id) + + if habit_list is None: + return {"error": "List not found"} + + # Check if habit belongs to user + if current_user not in habit_list.get_users(): + return {"error": "List does not belong to user"} + + habit_list.delete() + return {} + + @app.route('/reorder', methods=['POST']) @login_required def reorder_habits(): diff --git a/templates/components/delete_list.html b/templates/components/delete_list.html new file mode 100644 index 0000000..b140c83 --- /dev/null +++ b/templates/components/delete_list.html @@ -0,0 +1,20 @@ + + \ No newline at end of file diff --git a/templates/components/habit_lists.html b/templates/components/habit_lists.html index a111a4a..86b2653 100644 --- a/templates/components/habit_lists.html +++ b/templates/components/habit_lists.html @@ -15,7 +15,7 @@