|
@ -26,10 +26,6 @@ def AdminPage(): |
|
|
if adminuserform.validate_on_submit(): |
|
|
if adminuserform.validate_on_submit(): |
|
|
if adminuserform.delete.data: |
|
|
if adminuserform.delete.data: |
|
|
DeleteUsers(adminuserform) |
|
|
DeleteUsers(adminuserform) |
|
|
if adminuserform.tutors.data: |
|
|
|
|
|
ToggleUsersAsTutors(adminuserform, True) |
|
|
|
|
|
if adminuserform.nottutors.data: |
|
|
|
|
|
ToggleUsersAsTutors(adminuserform, False) |
|
|
|
|
|
|
|
|
|
|
|
template = render_template( |
|
|
template = render_template( |
|
|
"admin.html", |
|
|
"admin.html", |
|
@ -50,23 +46,6 @@ def DeleteUsers(adminuserform): |
|
|
userform.errors.append(f"User {useremail} deleted!") |
|
|
userform.errors.append(f"User {useremail} deleted!") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
ToggleUserTutorinDb(user, is_tutor) |
|
|
|
|
|
userform.errors.append(f"Is User {useremail} tutor {is_tutor}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ToggleUserTutorinDb(user, is_tutor): |
|
|
|
|
|
try: |
|
|
|
|
|
user.tutor = is_tutor |
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
|
|
|
db.session.rollback() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def DeleteUserFromDb(user): |
|
|
def DeleteUserFromDb(user): |
|
|
try: |
|
|
try: |
|
|