Beispiel #1
0
def submit_assignment(name):
    assign = get_assignment(name)
    group = Group.lookup(current_user, assign)
    user_ids = assign.active_user_ids(current_user.id)
    fs = assign.final_submission(user_ids)

    if not assign.uploads_enabled:
        flash("This assignment cannot be submitted online", 'warning')
        return redirect(url_for('.assignment', name=assign.name))
    if not assign.active:
        flash("It's too late to submit this assignment", 'warning')
        return redirect(url_for('.assignment', name=assign.name))

    form = UploadSubmissionForm()
    if form.validate_on_submit():
        files = request.files.getlist("upload_files")
        if files:
            templates = assign.files
            messages = {'file_contents': {}}
            for upload in files:
                data = upload.read()
                if len(data) > 2097152:
                    # File is too large (over 2 MB)
                    flash("{} is over the maximum file size limit of 2MB".format(upload.filename),
                          'danger')
                    return redirect(url_for('.submit_assignment', name=assign.name))
                messages['file_contents'][upload.filename] = str(data, 'latin1')
            if templates:
                missing = []
                for template in templates:
                    if template not in messages['file_contents']:
                        missing.append(template)
                if missing:
                    flash(("Missing files: {}. The following files are required: {}"
                           .format(', '.join(missing), ', '.join([t for t in templates]))
                           ), 'danger')
                    return redirect(url_for('.submit_assignment', name=assign.name))

            backup = make_backup(current_user, assign.id, messages, True)
            if form.flag_submission.data:
                assign.flag(backup.id, user_ids)
            if assign.autograding_key:
                try:
                    submit_continous(backup)
                except ValueError as e:
                    logger.warning('Web submission did not autograde', exc_info=True)
                    flash('Did not send to autograder: {}'.format(e), 'warning')

            flash("Uploaded submission (ID: {})".format(backup.hashid), 'success')
            return redirect(url_for('.assignment', name=assign.name))

    return render_template('student/assignment/submit.html', assignment=assign,
                           group=group, course=assign.course, form=form)
Beispiel #2
0
def staff_submit_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)
    # TODO: DRY - Unify with student upload code - should just be a function
    form = forms.UploadSubmissionForm()
    if form.validate_on_submit():
        files = request.files.getlist("upload_files")
        if files:
            templates = assign.files
            messages = {'file_contents': {}}
            for upload in files:
                data = upload.read()
                if len(data) > 2097152:
                    # File is too large (over 2 MB)
                    flash(("{} is over the maximum file size limit of 2MB"
                           .format(upload.filename)),
                          'danger')
                    return redirect(result_page)
                messages['file_contents'][upload.filename] = str(data, 'latin1')
            if templates:
                missing = []
                for template in templates:
                    if template not in messages['file_contents']:
                        missing.append(template)
                if missing:
                    flash(("Missing files: {}. The following files are required: {}"
                           .format(', '.join(missing), ', '.join([t for t in templates]))
                           ), 'danger')
                    return redirect(result_page)
            # use student, not current_user
            backup = ok_api.make_backup(student, assign.id, messages, True)
            if form.flag_submission.data:
                assign.flag(backup.id, user_ids)
            if assign.autograding_key:
                try:
                    submit_continous(backup)
                except ValueError as e:
                    flash('Did not send to autograder: {}'.format(e), 'warning')

            flash("Uploaded submission (ID: {})".format(backup.hashid), 'success')
            return redirect(result_page)
Beispiel #3
0
def staff_submit_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)
    # TODO: DRY - Unify with student upload code - should just be a function
    form = forms.UploadSubmissionForm()
    if form.validate_on_submit():
        files = request.files.getlist("upload_files")
        if files:
            templates = assign.files
            messages = {'file_contents': {}}
            for upload in files:
                data = upload.read()
                if len(data) > 2097152:
                    # File is too large (over 2 MB)
                    flash(("{} is over the maximum file size limit of 2MB"
                           .format(upload.filename)),
                          'danger')
                    return redirect(result_page)
                messages['file_contents'][upload.filename] = str(data, 'latin1')
            if templates:
                missing = []
                for template in templates:
                    if template not in messages['file_contents']:
                        missing.append(template)
                if missing:
                    flash(("Missing files: {}. The following files are required: {}"
                           .format(', '.join(missing), ', '.join([t for t in templates]))
                           ), 'danger')
                    return redirect(result_page)
            # use student, not current_user
            backup = ok_api.make_backup(student, assign.id, messages, True)
            if form.flag_submission.data:
                assign.flag(backup.id, user_ids)
            if assign.autograding_key:
                try:
                    submit_continous(backup)
                except ValueError as e:
                    flash('Did not send to autograder: {}'.format(e), 'warning')

            flash("Uploaded submission (ID: {})".format(backup.hashid), 'success')
            return redirect(result_page)
Beispiel #4
0
    def store_backup(self, user):
        args = self.parse_args()
        assignment = models.Assignment.name_to_assign_info(args['assignment'])

        if not assignment:
            raise ValueError('Assignment does not exist')
        lock_flag = not assignment['active']

        # Do not allow submissions after the lock date
        elgible_submit = args['submit'] and not lock_flag
        backup = make_backup(user, assignment['id'], args['messages'],
                             elgible_submit)
        if args['submit'] and lock_flag:
            raise ValueError('Late Submission')
        if elgible_submit and assignment['autograding_key']:
            submit_continous(backup)
        return backup
Beispiel #5
0
    def store_backup(self, user):
        args = self.parse_args()
        assignment = models.Assignment.name_to_assign_info(args['assignment'])

        if not assignment:
            raise ValueError('Assignment does not exist')
        lock_flag = not assignment['active']

        # Do not allow submissions after the lock date
        elgible_submit = args['submit'] and not lock_flag
        backup = make_backup(user, assignment['id'], args['messages'],
                             elgible_submit)
        if args['submit'] and lock_flag:
            raise ValueError('Late Submission of {}'.format(args['assignment']))
        if elgible_submit and assignment['autograding_key']:
            submit_continous(backup)
        return backup
Beispiel #6
0
def submit_assignment(name):
    assign = get_assignment(name)
    group = Group.lookup(current_user, assign)
    user_ids = assign.active_user_ids(current_user.id)
    fs = assign.final_submission(user_ids)

    if not assign.uploads_enabled:
        flash("This assignment cannot be submitted online", 'warning')
        return redirect(url_for('.assignment', name=assign.name))
    if not assign.active:
        flash("It's too late to submit this assignment", 'warning')
        return redirect(url_for('.assignment', name=assign.name))

    form = UploadSubmissionForm()
    if form.validate_on_submit():
        backup = Backup(
            submitter=current_user,
            assignment=assign,
            submit=True,
        )
        if form.upload_files.upload_backup_files(backup):
            db.session.add(backup)
            db.session.commit()
            if assign.autograding_key:
                try:
                    submit_continous(backup)
                except ValueError as e:
                    logger.warning('Web submission did not autograde',
                                   exc_info=True)
                    flash('Did not send to autograder: {}'.format(e),
                          'warning')
            flash('Uploaded submission', 'success')
            return redirect(
                url_for(
                    '.code',
                    name=assign.name,
                    submit=backup.submit,
                    bid=backup.id,
                ))

    return render_template('student/assignment/submit.html',
                           assignment=assign,
                           group=group,
                           course=assign.course,
                           form=form)
Beispiel #7
0
def submit_assignment(name):
    assign = get_assignment(name)
    group = Group.lookup(current_user, assign)
    user_ids = assign.active_user_ids(current_user.id)
    fs = assign.final_submission(user_ids)

    if not assign.uploads_enabled:
        flash("This assignment cannot be submitted online", 'warning')
        return redirect(url_for('.assignment', name=assign.name))
    if not assign.active:
        flash("It's too late to submit this assignment", 'warning')
        return redirect(url_for('.assignment', name=assign.name))

    form = UploadSubmissionForm()
    if form.validate_on_submit():
        backup = Backup(
            submitter=current_user,
            assignment=assign,
            submit=True,
        )
        if form.upload_files.upload_backup_files(backup):
            db.session.add(backup)
            db.session.commit()
            if assign.autograding_key:
                try:
                    submit_continous(backup)
                except ValueError as e:
                    logger.warning('Web submission did not autograde', exc_info=True)
                    flash('Did not send to autograder: {}'.format(e), 'warning')
            flash('Uploaded submission', 'success')
            return redirect(url_for(
                '.code',
                name=assign.name,
                submit=backup.submit,
                bid=backup.id,
            ))

    return render_template('student/assignment/submit.html', assignment=assign,
                           group=group, course=assign.course, form=form)
Beispiel #8
0
def staff_submit_backup(cid, email, 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'):
        return abort(404)
    student = User.lookup(email)
    if not student:
        abort(404)
    user_ids = assign.active_user_ids(student.id)
    # TODO: DRY - Unify with student upload code - should just be a function
    form = forms.StaffUploadSubmissionForm()
    if form.validate_on_submit():
        backup = Backup(
            submitter=student,
            creator=current_user,
            assignment=assign,
            submit=True,
            custom_submission_time=form.get_submission_time(assign),
        )
        if form.upload_files.upload_backup_files(backup):
            db.session.add(backup)
            db.session.commit()
            if assign.autograding_key:
                try:
                    autograder.submit_continous(backup)
                except ValueError as e:
                    flash('Did not send to autograder: {}'.format(e),
                          'warning')
            flash('Uploaded submission'.format(backup.hashid), 'success')
            return redirect(url_for('.grading', bid=backup.id))
    return render_template(
        'staff/student/submit.html',
        current_course=current_course,
        courses=courses,
        student=student,
        assignment=assign,
        upload_form=form,
    )
Beispiel #9
0
def submit_assignment(name):
    assign = get_assignment(name)
    group = Group.lookup(current_user, assign)
    user_ids = assign.active_user_ids(current_user.id)
    fs = assign.final_submission(user_ids)

    if not assign.uploads_enabled:
        flash("This assignment cannot be submitted online", 'warning')
        return redirect(url_for('.assignment', name=assign.name))
    if not assign.active:
        flash("It's too late to submit this assignment", 'warning')
        return redirect(url_for('.assignment', name=assign.name))

    form = UploadSubmissionForm()
    if form.validate_on_submit():
        files = request.files.getlist("upload_files")
        if files:
            templates = assign.files
            messages = {'file_contents': {}}
            for upload in files:
                data = upload.read()
                if len(data) > 2097152:
                    # File is too large (over 2 MB)
                    flash(
                        "{} is over the maximum file size limit of 2MB".format(
                            upload.filename), 'danger')
                    return redirect(
                        url_for('.submit_assignment', name=assign.name))
                messages['file_contents'][upload.filename] = str(
                    data, 'latin1')
            if templates:
                missing = []
                for template in templates:
                    if template not in messages['file_contents']:
                        missing.append(template)
                if missing:
                    flash((
                        "Missing files: {}. The following files are required: {}"
                        .format(', '.join(missing), ', '.join(
                            [t for t in templates]))), 'danger')
                    return redirect(
                        url_for('.submit_assignment', name=assign.name))

            backup = make_backup(current_user, assign.id, messages, True)
            if form.flag_submission.data:
                assign.flag(backup.id, user_ids)
            if assign.autograding_key:
                try:
                    submit_continous(backup)
                except ValueError as e:
                    logger.warning('Web submission did not autograde',
                                   exc_info=True)
                    flash('Did not send to autograder: {}'.format(e),
                          'warning')

            flash("Uploaded submission (ID: {})".format(backup.hashid),
                  'success')
            return redirect(url_for('.assignment', name=assign.name))

    return render_template('student/assignment/submit.html',
                           assignment=assign,
                           group=group,
                           course=assign.course,
                           form=form)