|
@ -28,7 +28,9 @@ def AdminPage(): |
|
|
if adminuserform.delete.data: |
|
|
if adminuserform.delete.data: |
|
|
DeleteUsers(adminuserform) |
|
|
DeleteUsers(adminuserform) |
|
|
if adminuserform.tutors.data: |
|
|
if adminuserform.tutors.data: |
|
|
MakeUsersTutors(adminuserform) |
|
|
ToggleUsersAsTutors(adminuserform, True) |
|
|
|
|
|
if adminuserform.nottutors.data: |
|
|
|
|
|
ToggleUsersAsTutors(adminuserform, False) |
|
|
|
|
|
|
|
|
template = render_template( |
|
|
template = render_template( |
|
|
"admin.html", |
|
|
"admin.html", |
|
@ -49,19 +51,19 @@ def DeleteUsers(adminuserform): |
|
|
userform.errors.append(f"User {useremail} deleted!") |
|
|
userform.errors.append(f"User {useremail} deleted!") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def MakeUsersTutors(adminuserform): |
|
|
def ToggleUsersAsTutors(adminuserform, is_tutor): |
|
|
for userform in adminuserform: |
|
|
for userform in adminuserform: |
|
|
if "user" in userform.id: |
|
|
if "user" in userform.id: |
|
|
if userform.data: |
|
|
if userform.data: |
|
|
useremail = userform.label.text |
|
|
useremail = userform.label.text |
|
|
user = User.query.filter_by(email=useremail).first() |
|
|
user = User.query.filter_by(email=useremail).first() |
|
|
MakeUserTutorinDb(user) |
|
|
ToggleUserTutorinDb(user, is_tutor) |
|
|
userform.errors.append(f"User {useremail} is now a tutor!") |
|
|
userform.errors.append(f"Is User {useremail} tutor {is_tutor}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def MakeUserTutorinDb(user): |
|
|
def ToggleUserTutorinDb(user, is_tutor): |
|
|
try: |
|
|
try: |
|
|
user.tutor = True |
|
|
user.tutor = is_tutor |
|
|
db.session.commit() |
|
|
db.session.commit() |
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
db.session.rollback() |
|
|
db.session.rollback() |
|
|