def staff_flag_backup(cid, email, aid): assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none() if not assign or not Assignment.can(assign, current_user, 'grade'): return abort(404) result_page = url_for('.student_assignment_detail', cid=cid, email=email, aid=aid) student = User.lookup(email) if not student: abort(404) user_ids = assign.active_user_ids(student.id) bid = request.form.get('bid') form = forms.CSRFForm() if form.validate_on_submit(): backup = Backup.query.filter_by(id=utils.decode_id(bid), assignment=assign).one_or_none() if not backup: flash('{} does not exist'.format(bid, 'error')) return redirect(result_page) if not backup.flagged: result = assign.flag(backup.id, user_ids) flash('Flagged backup {} for grading'.format(bid), 'success') else: result = assign.unflag(backup.id, user_ids) flash('Removed grading flag on {}'.format(bid), 'success') return redirect(result_page)
def enrollment(cid): courses, current_course = get_courses(cid) form = forms.EnrollmentForm() if form.validate_on_submit(): email, role = form.email.data, form.role.data Enrollment.enroll_from_form(cid, form) flash("Added {email} as {role}".format( email=email, role=role), "success") students = (Enrollment.query.options(db.joinedload('user')) .filter_by(course_id=cid, role=STUDENT_ROLE) .order_by(Enrollment.created.desc()) .all()) staff = (Enrollment.query.options(db.joinedload('user')) .filter(Enrollment.course_id == cid, Enrollment.role.in_(STAFF_ROLES)) .all()) lab_assistants = (Enrollment.query.options(db.joinedload('user')) .filter_by(course_id=cid, role=LAB_ASSISTANT_ROLE) .order_by(Enrollment.created.desc()) .all()) return render_template('staff/course/enrollment/enrollment.html', enrollments=students, staff=staff, lab_assistants=lab_assistants, form=form, unenroll_form=forms.CSRFForm(), courses=courses, current_course=current_course)
def staff_group_remove(cid, email, aid): assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none() if not assign or not Assignment.can(assign, current_user, 'grade'): return abort(404) student = User.lookup(email) if not student: abort(404) result_page = url_for('.student_assignment_detail', cid=cid, email=email, aid=aid) form = forms.CSRFForm() if form.validate_on_submit(): target = User.lookup(request.form['target']) if not target: flash('{} does not exist'.format(request.form['target']), 'error') return redirect(result_page) try: Group.force_remove(current_user, student, target, assign) except BadRequest as e: flash("Error: {}".format(str(e.description)), 'error') return redirect(result_page)
def student_assignment_detail(cid, email, aid): courses, current_course = get_courses(cid) page = request.args.get('page', 1, type=int) assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none() if not assign or not Assignment.can(assign, current_user, 'grade'): flash('Cannot access assignment', 'error') return abort(404) student = User.lookup(email) if not student.is_enrolled(cid): flash("This user is not enrolled", 'warning') assignment_stats = assign.user_status(student, staff_view=True) user_ids = assign.active_user_ids(student.id) latest = assignment_stats.final_subm or assign.backups(user_ids).first() stats = { 'num_backups': assign.backups(user_ids).count(), 'num_submissions': assign.submissions(user_ids).count(), 'current_q': None, 'attempts': None, 'latest': latest, 'analytics': latest and latest.analytics() } backups = (Backup.query.options( db.joinedload('scores'), db.joinedload('submitter')).filter( Backup.submitter_id.in_(user_ids), Backup.assignment_id == assign.id).order_by( Backup.flagged.desc(), Backup.submit.desc(), Backup.created.desc())) paginate = backups.paginate(page=page, per_page=15) if stats['analytics']: stats['current_q'] = stats['analytics'].get('question') stats['attempts'] = (stats['analytics'].get('history', {}).get('all_attempts')) return render_template('staff/student/assignment.html', courses=courses, current_course=current_course, student=student, assignment=assign, add_member_form=forms.StaffAddGroupFrom(), paginate=paginate, csrf_form=forms.CSRFForm(), stats=stats, assign_status=assignment_stats)
def autograde(cid, aid): courses, current_course = get_courses(cid) assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none() if not assign or not Assignment.can(assign, current_user, 'grade'): flash('Cannot access assignment', 'error') return abort(404) form = forms.CSRFForm() if form.validate_on_submit(): try: autograder.autograde_assignment(assign) flash('Submitted to the autograder', 'success') except ValueError as e: flash(str(e), 'error') return redirect(url_for('.assignment', cid=cid, aid=aid))
def autograde_backup(bid): backup = Backup.query.options(db.joinedload('assignment')).get(bid) if not backup: abort(404) if not Backup.can(backup, current_user, 'grade'): flash("You do not have permission to score this assignment.", "warning") abort(401) form = forms.CSRFForm() if form.validate_on_submit(): try: autograder.autograde_backup(backup) flash('Submitted to the autograder', 'success') except ValueError as e: flash(str(e), 'error') return redirect(url_for('.grading', bid=bid))