Merge remote-tracking branch 'origin/master'

This commit is contained in:
nikolaswollenberg 2024-03-07 19:22:48 +01:00
commit a46b464ca6
5 changed files with 54 additions and 12 deletions

43
app.py
View File

@ -142,7 +142,7 @@ def index():
# Sort habits by whether they have been checked today and then by slot # Sort habits by whether they have been checked today and then by slot
for habit_list in habit_lists: for habit_list in habit_lists:
habit_list.habits = sorted(habit_list.get_habits(), key=lambda habit: (not habit.checked, habit.slot)) habit_list.habits = sorted(habit_list.get_habits(), key=lambda habit: (habit.checked, habit.slot))
days = {"Monday": "Montag", "Tuesday": "Dienstag", "Wednesday": "Mittwoch", "Thursday": "Donnerstag", days = {"Monday": "Montag", "Tuesday": "Dienstag", "Wednesday": "Mittwoch", "Thursday": "Donnerstag",
"Friday": "Freitag", "Saturday": "Samstag", "Sunday": "Sonntag"} "Friday": "Freitag", "Saturday": "Samstag", "Sunday": "Sonntag"}
@ -297,6 +297,7 @@ def habit_list_create():
@app.route('/profile') @app.route('/profile')
@login_required @login_required
def profile(): def profile():
print(current_user.name, current_user.email)
return render_template( return render_template(
"profile.html", "profile.html",
name=current_user.name, name=current_user.name,
@ -794,6 +795,46 @@ def user_leave():
habit_list.remove_user(current_user.id) habit_list.remove_user(current_user.id)
return redirect(url_for("index")) return redirect(url_for("index"))
@app.route('/accept-list', methods=['POST'])
@login_required
def accept_list():
list_id = request.form.get('list_id')
habit_list = HabitList.get(int(list_id))
users = habit_list.get_users()
# Check if user is part of the list
found = False
for user in users:
if user.id == habit_list.id:
found = True
break
if not found:
return redirect(url_for("index"))
current_user.accept_List(list_id)
return {}
@app.route('/deny-list', methods=['POST'])
@login_required
def deny_list():
list_id = request.form.get('list_id')
habit_list = HabitList.get(int(list_id))
users = habit_list.get_users()
# Check if user is part of the list
found = False
for user in users:
if user.id == habit_list.id:
found = True
break
if not found:
return redirect(url_for("index"))
habit_list.remove_user(current_user.id)
return {}
# Run the application # Run the application
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -3,7 +3,7 @@ from dataclasses import dataclass
from models.Habit import Habit from models.Habit import Habit
from models.User import User from models.User import User
from db.SQLiteClient import (create_habitList, get_habitList, get_habits, get_users, add_user, remove_user, from db.SQLiteClient import (create_habitList, get_habitList, get_habits, get_users, add_user, remove_user,
update_habitList, delete_habitList, accept_List) update_habitList, delete_habitList)
@dataclass @dataclass
@ -66,9 +66,6 @@ class HabitList:
else: else:
return None return None
def accept_List(self, user:User):
accept_List(self.id, user.id)
# Removes a User from the HabitList # Removes a User from the HabitList
def remove_user(self, user_id): def remove_user(self, user_id):
remove_user(self.id, user_id) remove_user(self.id, user_id)

View File

@ -2,7 +2,7 @@ from datetime import datetime
from flask_login import UserMixin from flask_login import UserMixin
from db.SQLiteClient import (create_user, get_user, get_user_by_email, update_user, delete_user, from db.SQLiteClient import (create_user, get_user, get_user_by_email, update_user, delete_user,
get_habitLists, get_heatmap_value) get_habitLists, get_heatmap_value, accept_List)
class User(UserMixin): class User(UserMixin):
@ -75,4 +75,7 @@ class User(UserMixin):
heatmap.append(value) heatmap.append(value)
heatmap.reverse() heatmap.reverse()
day = 27-weekday day = 27-weekday
return heatmap, day return heatmap, day
def accept_List(self, HabitList_id):
accept_List(self.id, HabitList_id)

View File

@ -35,9 +35,9 @@ document.addEventListener("DOMContentLoaded", function() {
// Add event listener to edit button to open modal // Add event listener to edit button to open modal
editButton.addEventListener("click", function() { editButton.addEventListener("click", function() {
editModal.show(); editModal.show();
document.getElementById("newName").value = "{{ name }}"; // document.getElementById("newName").value = "{{ name }}";
document.getElementById("newEmail").value = "{{ email }}"; // document.getElementById("newEmail").value = "{{ email }}";
document.getElementById("password").value = ""; // document.getElementById("password").value = "";
}); });
// Add event listener to save changes button to submit form // Add event listener to save changes button to submit form

View File

@ -77,12 +77,12 @@
<form id="editForm" action="/profile" method="POST"> <form id="editForm" action="/profile" method="POST">
<div class="form-group"> <div class="form-group">
<label for="newName">Neuer Name:</label> <label for="newName">Neuer Name:</label>
<input type="text" class="form-control" id="newName" name="newName" value="{{name}}" autocomplete="username"> <input type="text" class="form-control" id="newName" name="newName" value="{{ name }}" autocomplete="username">
<div class="invalid-feedback" id="nameFeedback"></div> <div class="invalid-feedback" id="nameFeedback"></div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="newEmail">Neue E-Mail:</label> <label for="newEmail">Neue E-Mail:</label>
<input type="email" class="form-control" id="newEmail" name="newEmail" value="{{email}}" autocomplete="username"> <input type="email" class="form-control" id="newEmail" name="newEmail" value="{{ email }}" autocomplete="username">
<div class="invalid-feedback" id="emailFeedback"></div> <div class="invalid-feedback" id="emailFeedback"></div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -102,4 +102,5 @@
<script src="../static/script/script-profile.js"></script> <script src="../static/script/script-profile.js"></script>
{% endblock %} {% endblock %}