forked from crunk/distribusi-verse
turn users as tutors on or off
This commit is contained in:
parent
fd9f623193
commit
f574f67dba
@ -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()
|
||||
|
@ -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")
|
||||
|
@ -20,7 +20,7 @@ from flask_bcrypt import generate_password_hash
|
||||
from app import db
|
||||
|
||||
|
||||
def ResetPassword(path):
|
||||
def ResetPassword(path):
|
||||
linkvalid = False
|
||||
user = User.query.filter_by(resethash=path).first()
|
||||
if user is None:
|
||||
|
@ -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…
Reference in New Issue
Block a user