Esempio n. 1
0
def update_submission_status(lti, lti_exception=None):
    # Get parameters
    submission_id = maybe_int(request.values.get("submission_id"))
    status = request.values.get('status')
    course_id = get_course_id()
    user, user_id = get_user()
    submission = Submission.by_id(submission_id)
    # Check resource exists
    check_resource_exists(submission, "Submission", submission_id)
    # Verify permissions
    if submission.user_id != user_id and not user.is_grader(
            submission.course_id):
        return ajax_failure(
            "This is not your submission and you are not a grader in its course."
        )
    # Do action
    success = submission.update_submission_status(status)
    make_log_entry(submission.assignment_id,
                   submission.assignment_version,
                   course_id,
                   user_id,
                   "Submit",
                   "answer.py",
                   category=status,
                   message=str(success))
    return ajax_success({"success": success})
Esempio n. 2
0
 def delete(self, review_id):
     user, user_id = get_user()
     review = Review.by_id(review_id)
     check_resource_exists(review, "Review", review_id)
     submission = Submission.by_id(review.submission_id)
     check_resource_exists(submission, "Submission", review.submission_id)
     require_course_grader(user, submission.course_id)
     review.delete()
     return ajax_success(dict(success=True))
Esempio n. 3
0
 def get_one(self, review_id):
     user, user_id = get_user()
     review = Review.by_id(review_id)
     check_resource_exists(review, "Review", review_id)
     submission = Submission.by_id(review.submission_id)
     check_resource_exists(submission, "Submission", review.submission_id)
     if submission.user_id != user_id:
         require_course_grader(user, submission.course_id)
     return ajax_success(dict(review=review.encode_json()))
Esempio n. 4
0
    def decorated_function(self, *args, **kwargs):
        submission_id = args[0]
        submission = Submission.by_id(submission_id)

        if submission:
            kwargs['submission'] = submission
            return f(self, *args, **kwargs)
        else:
            self.error(404)
            return
Esempio n. 5
0
def update_grading_status(lti, lti_exception=None):
    submission_id = maybe_int(request.values.get("submission_id"))
    # TODO: Pretty sure multiple assignments are broken for grading
    assignment_group_id = maybe_int(request.values.get('assignment_group_id'))
    new_grading_status = request.values.get("new_grading_status")
    user, user_id = get_user()
    submission = Submission.by_id(submission_id)
    # Check resource exists
    check_resource_exists(submission, "Submission", submission_id)
    # Verify permissions
    if not user.is_grader(submission.course_id):
        return ajax_failure(
            "This is not your submission and you are not a grader in its course."
        )
    submission.update_grading_status(new_grading_status)
    if submission.grading_status != GradingStatuses.FULLY_GRADED:
        return ajax_success({'new_status': new_grading_status})
    # Do action
    if assignment_group_id is None:
        assignment_group_id = submission.assignment_group_id
    error = "Generic LTI Failure - perhaps not logged into LTI session?"
    try:
        success, score = lti_post_grade(lti, submission, None,
                                        assignment_group_id,
                                        submission.user_id,
                                        submission.course_id)
    except LTIPostMessageException as e:
        success = False
        error = str(e)
    if success:
        make_log_entry(submission.assignment_id,
                       submission.assignment_version,
                       submission.course_id,
                       user_id,
                       "X-Submission.LMS",
                       "answer.py",
                       message=str(score))
        return ajax_success({"submitted": True, "new_status": "FullyGraded"})
    else:
        submission.update_grading_status(GradingStatuses.FAILED)
        make_log_entry(submission.assignment_id,
                       submission.assignment_version,
                       submission.course_id,
                       user_id,
                       "X-Submission.LMS.Failure",
                       "answer.py",
                       message=error)
        return ajax_failure({
            "submitted": False,
            "message": error,
            "new_status": "Failed"
        })
Esempio n. 6
0
def update_submission_status():
    submission_id = maybe_int(request.values.get("submission_id"))
    new_submission_status = request.values.get("new_submission_status")
    user, user_id = get_user()
    submission = Submission.by_id(submission_id)
    # Check resource exists
    check_resource_exists(submission, "Submission", submission_id)
    # Verify permissions
    if not user.is_grader(submission.course_id):
        return ajax_failure(
            "You are not a grader in this submission's course.")
    submission.update_submission_status(new_submission_status)
    return ajax_success({'new_status': new_submission_status})
Esempio n. 7
0
 def put(self, review_id):
     user, user_id = get_user()
     review = Review.by_id(review_id)
     check_resource_exists(review, "Review", review_id)
     submission = Submission.by_id(review.submission_id)
     check_resource_exists(submission, "Submission", review.submission_id)
     require_course_grader(user, submission.course_id)
     review_data = request.json.copy()
     del review_data['id']
     fix_nullables(review_data)
     review_data['author_id'] = user_id
     edited_review = review.edit(review_data)
     return ajax_success(dict(review=edited_review.encode_json()))
Esempio n. 8
0
 def get_all(self):
     submission_id = maybe_int(request.values.get('submission_id'))
     user, user_id = get_user()
     if submission_id is None:
         reviews = Review.get_generic_reviews()
     else:
         submission = Submission.by_id(submission_id)
         check_resource_exists(submission, "Submission", submission_id)
         reviews = Review.get_for_submission(submission_id)
         if submission.user_id != user_id:
             require_course_grader(user, submission.course_id)
     return ajax_success(
         dict(reviews=[review.encode_json() for review in reviews]))
Esempio n. 9
0
 def post(self):
     user, user_id = get_user()
     submission_id = maybe_int(request.values.get('submission_id'))
     submission = Submission.by_id(submission_id)
     check_resource_exists(submission, "Submission", submission_id)
     require_course_grader(user, submission.course_id)
     review_data = request.values.copy()
     del review_data['id']
     review_data['author_id'] = user_id
     review_data['submission_version'] = submission.version
     review_data['assignment_version'] = submission.assignment_version
     fix_nullables(review_data)
     new_review = Review.new(review_data)
     return ajax_success(dict(review=new_review.encode_json()))
Esempio n. 10
0
def save_image():
    # Get parameters
    submission_id = maybe_int(request.values.get("submission_id"))
    directory = request.values.get('directory')
    image = request.values.get('image')
    course_id = get_course_id()
    user, user_id = get_user()
    submission = Submission.by_id(submission_id)
    # Check resource exists
    check_resource_exists(submission, "Submission", submission_id)
    # Verify permissions
    if submission.user_id != user_id and not user.is_grader(submission.course_id):
        return ajax_failure("This is not your submission and you are not a grader in its course.")
    # Do action
    success = submission.save_image(directory, image)
    make_log_entry(submission.assignment_id, submission.assignment_version,
                   course_id, user_id, "X-Image.Save", directory)
    return ajax_success({"success": success})
Esempio n. 11
0
def update_submission(lti, lti_exception=None):
    # Get parameters
    submission_id = maybe_int(request.values.get("submission_id"))
    lis_result_sourcedid = request.values.get('lis_result_sourcedid')
    assignment_group_id = maybe_int(request.values.get('assignment_group_id'))
    score = float(request.values.get('score', '0'))
    correct = maybe_bool(request.values.get("correct"))
    # TODO: Only send image if the assignment settings starts as Block or Split
    image = request.values.get('image', "")
    hidden_override = maybe_bool(request.values.get('hidden_override'))
    force_update = maybe_bool(request.values.get('force_update'))
    course_id = get_course_id()
    user, user_id = get_user()
    submission = Submission.by_id(submission_id)
    # Check resource exists
    check_resource_exists(submission, "Submission", submission_id)
    # Verify permissions
    if submission.user_id != user_id and not user.is_grader(submission.course_id):
        return ajax_failure("This is not your submission and you are not a grader in its course.")
    # Do action
    was_changed = submission.update_submission(score, correct)
    if assignment_group_id is None:
        assignment_group_id = submission.assignment_group_id
    # TODO: Document that we currently only pass back grade if it changed
    # TODO: If failure on previous submission grading, then retry
    if was_changed or force_update:
        submission.save_block_image(image)
        error = "Generic LTI Failure - perhaps not logged into LTI session?"
        try:
            success, score = lti_post_grade(lti, submission, lis_result_sourcedid, assignment_group_id,
                                     submission.user_id, submission.course_id)
        except LTIPostMessageException as e:
            success = False
            error = str(e)
        if success:
            make_log_entry(submission.assignment_id, submission.assignment_version,
                           course_id, user_id, "X-Submission.LMS", "answer.py", message=str(score))
        else:
            submission.update_grading_status(GradingStatuses.FAILED)
            make_log_entry(submission.assignment_id, submission.assignment_version,
                           course_id, user_id, "X-Submission.LMS.Failure", "answer.py", message=error)
            return ajax_failure({"submitted": False, "changed": was_changed, "message": error})
    return ajax_success({"submitted": was_changed or force_update, "changed": was_changed})
Esempio n. 12
0
def view_submission():
    submission_id = request.values.get('submission_id')
    viewer, viewer_id = get_user()
    embed = maybe_bool(request.values.get('embed'))
    submission = Submission.by_id(submission_id)
    # Check exists
    check_resource_exists(submission, "Submission", submission_id)
    # Check permissions
    if submission.user_id != viewer_id:
        require_course_grader(viewer, submission.course_id)
    is_grader = viewer.is_grader(submission.course_id)
    tags = []
    if is_grader:
        tags = [tag.encode_json() for tag in AssignmentTag.get_all()]
    # Do action
    return render_template("reports/alone.html", embed=embed,
                           submission=submission, assignment=submission.assignment,
                           is_grader=is_grader, tags=tags,
                           user_id=submission.user_id, course_id=submission.course_id)
Esempio n. 13
0
def load_submission(lti=lti):
    submission_id = int(request.args.get('submission_id'))
    embed = maybe_bool(request.values.get('embed'))
    course_id = get_course_id(True)
    user, user_id = get_user()
    submission = Submission.by_id(submission_id)
    read_only = maybe_bool(request.values.get('read_only', "true"))
    # Check that the resource exists
    check_resource_exists(submission, "Submission", submission_id)
    # If it is this user's submission, redirect to load the assignment
    if submission.user_id == user_id:
        if course_id is None:
            course_id = submission.course_id
        return redirect(
            url_for('blockpy.load',
                    assignment_id=submission.assignment.id,
                    course_id=course_id))
    # Check that it is public or you are a grader
    elif user.is_grader(submission.course_id):
        role = 'grader'
    elif not submission.assignment.public:
        # TODO: Handle this more gracefully
        return ajax_failure(
            "Cannot view submission. This is not a public submission, and you do not own the submission, and you are "
            "not an instructor in its course.")
    else:
        role = 'anonymous'
    # Get the assignment
    assignment_data = submission.assignment.for_editor(submission.user_id,
                                                       submission.course_id)
    return load_editor(
        lti, {
            "user": user,
            "user_id": user_id,
            "embed": embed,
            "read_only": read_only,
            "current_submission_id": submission_id,
            "course_id": course_id,
            "role": role,
            "assignment_group_id": None,
            "assignment_data": assignment_data
        })