def admin(): """List of all students and groups. Group, student, and instructor management forms""" check_admin() db_ses = db.session # Queries for the tables of students and groups students = db_ses.query(User.id, User.username, User.email, User.is_static).filter(User.is_instructor == False) instructors = db_ses.query(User.id, User.username, User.email).filter(User.is_instructor == True) groups = StudentGroups.query.all() groupNames = [] users_per_group = {} for g in groups: groupNames.append(g.name) for name in groupNames: users_per_group[name] = db_ses.query(User.id, User.username, User.email, User.is_static).filter( StudentGroups.name == name, StudentGroups.id == GroupUsers.group_id, GroupUsers.user_id == User.id, ) if request.method == "GET": groupMaker = GroupForm() userAdder = addUsersForm() instructorManager = manageInstructorForm() groupEraser = deleteGroupForm() return render_template( "dashboard/admin.html", groupMaker=groupMaker, userAdder=userAdder, instructorManager=instructorManager, groups=groups, students=students, instructors=instructors, usersPGroup=users_per_group, groupEraser=groupEraser ) elif request.method == "POST": ajax = process_request(request.form) if ajax: temp = ajax[0] if temp == 'utils/create_group_response.html': if len(ajax) == 1: return render_template(temp) elif len(ajax) < 4: return render_template(temp, group=ajax[1], users=ajax[2]) else: return render_template(temp, group=ajax[1], users=ajax[2], pairs=ajax[3]) elif temp == 'utils/manage_student_response.html': if len(ajax) == 1: return render_template(temp) else: return render_template(temp, group=ajax[1], users=ajax[2]) else: return redirect(url_for("dashboard.admin"))
def process_manInst(): # Form to give a specified user instructor permissions | # manageInstructorForm mI = manageInstructorForm(request.form) if request.form.get("promote") == "true": if mI.validate_on_submit(): uName = mI.uName.data # string1.data # user = User.query.filter_by(username=uName).first() user.update(is_instructor=True) flash("Made {0} an Instructor.".format(uName)) else: flash_errors(mI) elif request.form.get("promote") == "false": if mI.validate_on_submit(): uName = mI.uName.data # string1.data # user = User.query.filter_by(username=uName).first() user.update(is_instructor=False) flash("Demoted {0} from Instructor status.".format(uName)) else: flash_errors(mI)