Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a46b464ca6
43
app.py
43
app.py
@ -142,7 +142,7 @@ def index():
|
||||
|
||||
# Sort habits by whether they have been checked today and then by slot
|
||||
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",
|
||||
"Friday": "Freitag", "Saturday": "Samstag", "Sunday": "Sonntag"}
|
||||
@ -297,6 +297,7 @@ def habit_list_create():
|
||||
@app.route('/profile')
|
||||
@login_required
|
||||
def profile():
|
||||
print(current_user.name, current_user.email)
|
||||
return render_template(
|
||||
"profile.html",
|
||||
name=current_user.name,
|
||||
@ -794,6 +795,46 @@ def user_leave():
|
||||
habit_list.remove_user(current_user.id)
|
||||
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
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||
from models.Habit import Habit
|
||||
from models.User import 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
|
||||
@ -66,9 +66,6 @@ class HabitList:
|
||||
else:
|
||||
return None
|
||||
|
||||
def accept_List(self, user:User):
|
||||
accept_List(self.id, user.id)
|
||||
|
||||
# Removes a User from the HabitList
|
||||
def remove_user(self, user_id):
|
||||
remove_user(self.id, user_id)
|
||||
|
||||
@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from flask_login import UserMixin
|
||||
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):
|
||||
@ -75,4 +75,7 @@ class User(UserMixin):
|
||||
heatmap.append(value)
|
||||
heatmap.reverse()
|
||||
day = 27-weekday
|
||||
return heatmap, day
|
||||
return heatmap, day
|
||||
|
||||
def accept_List(self, HabitList_id):
|
||||
accept_List(self.id, HabitList_id)
|
||||
|
||||
@ -35,9 +35,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
// Add event listener to edit button to open modal
|
||||
editButton.addEventListener("click", function() {
|
||||
editModal.show();
|
||||
document.getElementById("newName").value = "{{ name }}";
|
||||
document.getElementById("newEmail").value = "{{ email }}";
|
||||
document.getElementById("password").value = "";
|
||||
// document.getElementById("newName").value = "{{ name }}";
|
||||
// document.getElementById("newEmail").value = "{{ email }}";
|
||||
// document.getElementById("password").value = "";
|
||||
});
|
||||
|
||||
// Add event listener to save changes button to submit form
|
||||
|
||||
@ -77,12 +77,12 @@
|
||||
<form id="editForm" action="/profile" method="POST">
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
@ -102,4 +102,5 @@
|
||||
|
||||
<script src="../static/script/script-profile.js"></script>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user