Browse Source

turn users as tutors on or off

current_wdka_release
crunk 3 years ago
parent
commit
f574f67dba
  1. 14
      verse/adminpage.py
  2. 4
      verse/forms/adminuserform.py
  3. 3
      verse/templates/admin.html

14
verse/adminpage.py

@ -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()

4
verse/forms/adminuserform.py

@ -22,6 +22,8 @@ class AdminUserForm(FlaskForm):
return UserListForm()
tutors = SubmitField("Are Tutors")
tutors = SubmitField("Are tutors")
nottutors = SubmitField("Are not tutors")
delete = SubmitField("Delete")

3
verse/templates/admin.html

@ -56,6 +56,9 @@
<fieldset class="button required">
{{ adminuserform.tutors }}
</fieldset>
<fieldset class="button required">
{{ adminuserform.nottutors }}
</fieldset>
<fieldset class="button required">
{{ adminuserform.delete }}
</fieldset>

Loading…
Cancel
Save