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