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:
|
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()
|
||||||
|
@ -22,6 +22,8 @@ class AdminUserForm(FlaskForm):
|
|||||||
|
|
||||||
return UserListForm()
|
return UserListForm()
|
||||||
|
|
||||||
tutors = SubmitField("Are Tutors")
|
tutors = SubmitField("Are tutors")
|
||||||
|
|
||||||
|
nottutors = SubmitField("Are not tutors")
|
||||||
|
|
||||||
delete = SubmitField("Delete")
|
delete = SubmitField("Delete")
|
||||||
|
@ -20,7 +20,7 @@ from flask_bcrypt import generate_password_hash
|
|||||||
from app import db
|
from app import db
|
||||||
|
|
||||||
|
|
||||||
def ResetPassword(path):
|
def ResetPassword(path):
|
||||||
linkvalid = False
|
linkvalid = False
|
||||||
user = User.query.filter_by(resethash=path).first()
|
user = User.query.filter_by(resethash=path).first()
|
||||||
if user is None:
|
if user is None:
|
||||||
|
@ -56,6 +56,9 @@
|
|||||||
<fieldset class="button required">
|
<fieldset class="button required">
|
||||||
{{ adminuserform.tutors }}
|
{{ adminuserform.tutors }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset class="button required">
|
||||||
|
{{ adminuserform.nottutors }}
|
||||||
|
</fieldset>
|
||||||
<fieldset class="button required">
|
<fieldset class="button required">
|
||||||
{{ adminuserform.delete }}
|
{{ adminuserform.delete }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
Loading…
Reference in New Issue
Block a user