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
|
# 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__':
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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):
|
||||||
@ -76,3 +76,6 @@ class User(UserMixin):
|
|||||||
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)
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -102,4 +102,5 @@
|
|||||||
|
|
||||||
<script src="../static/script/script-profile.js"></script>
|
<script src="../static/script/script-profile.js"></script>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user