def save_grade(request): """ Supports POST requests with the following arguments: location: string grader_id: int submission_id: int score: int feedback: string submission_key : string Returns json dict with keys version: int success: bool error: string, present if not success """ if request.method != "POST": raise Http404 post_data = request.POST.dict().copy() for tag in ['location', 'grader_id', 'submission_id', 'submission_key', 'score', 'feedback', 'submission_flagged']: if not tag in post_data: return util._error_response("Cannot find needed key {0} in request.".format(tag), _INTERFACE_VERSION) location = post_data['location'] grader_id = post_data['grader_id'] submission_id = post_data['submission_id'] #Submission key currently unused, but plan to use it for validation in the future. submission_key = post_data['submission_key'] score = post_data['score'] #This is done to ensure that response is properly formatted on the lms side. feedback_dict = post_data['feedback'] rubric_scores_complete = request.POST.get('rubric_scores_complete', False) rubric_scores = request.POST.getlist('rubric_scores', []) is_submission_flagged = request.POST.get('submission_flagged', False) if isinstance(is_submission_flagged, basestring): is_submission_flagged = (is_submission_flagged.lower()=="true") status = GraderStatus.success confidence = 1.0 is_answer_unknown = request.POST.get('answer_unknown', False) if isinstance(is_answer_unknown, basestring): is_answer_unknown = (is_answer_unknown.lower()=="true") if is_answer_unknown: status = GraderStatus.failure confidence = 0.0 try: score = int(score) except ValueError: #Score may not be filled out if answer_unknown or flagged if is_answer_unknown or is_submission_flagged: score = 0 else: return util._error_response("Expected integer score. Got {0}".format(score), _INTERFACE_VERSION) try: sub=Submission.objects.get(id=submission_id) except Exception: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": "Submission id {0} is not valid.".format(submission_id)} ) #Patch to handle rubric scores in the case of "I don't know" or flagging if scores aren't filled out if is_answer_unknown or is_submission_flagged and len(rubric_scores)==0: success, targets=rubric_functions.generate_targets_from_rubric(sub.rubric) rubric_scores = [0 for l in targets] rubric_scores_complete = True success, error_message = grader_util.validate_rubric_scores(rubric_scores, rubric_scores_complete, sub) if not success: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": error_message} ) d = {'submission_id': submission_id, 'score': score, 'feedback': feedback_dict, 'grader_id': grader_id, 'grader_type': 'PE', # Humans always succeed (if they grade at all)... 'status': status, # ...and they're always confident too. 'confidence': confidence, #And they don't make any errors 'errors' : "", 'rubric_scores_complete' : rubric_scores_complete, 'rubric_scores' : rubric_scores, 'is_submission_flagged' : is_submission_flagged, } #Currently not posting back to LMS. Only saving grader object, and letting controller decide when to post back. (success, header) = grader_util.create_and_handle_grader_object(d) if not success: return util._error_response("There was a problem saving the grade. Contact support.", _INTERFACE_VERSION) #xqueue_session=util.xqueue_login() #error,msg = util.post_results_to_xqueue(xqueue_session,json.dumps(header),json.dumps(post_data)) util.log_connection_data() return util._success_response({'msg': "Posted to queue."}, _INTERFACE_VERSION)
def save_grade(request): """ Supports POST requests with the following arguments: course_id: int grader_id: int submission_id: int score: int feedback: string Returns json dict with keys version: int success: bool error: string, present if not success """ if request.method != "POST": return util._error_response("Request needs to be GET", _INTERFACE_VERSION) course_id = request.POST.get('course_id') grader_id = request.POST.get('grader_id') submission_id = request.POST.get('submission_id') score = request.POST.get('score') feedback = request.POST.get('feedback') skipped = request.POST.get('skipped')=="True" rubric_scores_complete = request.POST.get('rubric_scores_complete', False) rubric_scores = request.POST.getlist('rubric_scores', []) is_submission_flagged = request.POST.get('submission_flagged', False) if isinstance(is_submission_flagged, basestring): is_submission_flagged = is_submission_flagged.lower() == 'true' if (# These have to be truthy not (course_id and grader_id and submission_id) or # These have to be non-None score is None or feedback is None): return util._error_response("required_parameter_missing", _INTERFACE_VERSION) if skipped: success, sub = staff_grading_util.set_instructor_grading_item_back_to_preferred_grader(submission_id) if not success: return util._error_response(sub, _INTERFACE_VERSION) return util._success_response({}, _INTERFACE_VERSION) try: score = int(score) except ValueError: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": "Expected integer score. Got {0}".format(score)}) try: sub=Submission.objects.get(id=submission_id) except Exception: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": "Submission id {0} is not valid.".format(submission_id)} ) first_sub_for_location=Submission.objects.filter(location=sub.location).order_by('date_created')[0] rubric= first_sub_for_location.rubric rubric_success, parsed_rubric = rubric_functions.parse_rubric(rubric) if rubric_success: success, error_message = grader_util.validate_rubric_scores(rubric_scores, rubric_scores_complete, sub) if not success: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": error_message} ) d = {'submission_id': submission_id, 'score': score, 'feedback': feedback, 'grader_id': grader_id, 'grader_type': 'IN', # Humans always succeed (if they grade at all)... 'status': GraderStatus.success, # ...and they're always confident too. 'confidence': 1.0, #And they don't make errors 'errors' : "", 'rubric_scores_complete' : rubric_scores_complete, 'rubric_scores' : rubric_scores, 'is_submission_flagged' : is_submission_flagged, } success, header = grader_util.create_and_handle_grader_object(d) if not success: return util._error_response("grade_save_error", _INTERFACE_VERSION, data={'msg': 'Internal error'}) util.log_connection_data() return util._success_response({}, _INTERFACE_VERSION)
def save_grade(request): """ Supports POST requests with the following arguments: location: string grader_id: int submission_id: int score: int feedback: string submission_key : string Returns json dict with keys version: int success: bool error: string, present if not success """ if request.method != "POST": raise Http404 post_data = request.POST.dict().copy() log.debug(post_data) for tag in [ 'location', 'grader_id', 'submission_id', 'submission_key', 'score', 'feedback', 'submission_flagged' ]: if not tag in post_data: return util._error_response( "Cannot find needed key {0} in request.".format(tag), _INTERFACE_VERSION) location = post_data['location'] grader_id = post_data['grader_id'] submission_id = post_data['submission_id'] #Submission key currently unused, but plan to use it for validation in the future. submission_key = post_data['submission_key'] score = post_data['score'] #This is done to ensure that response is properly formatted on the lms side. feedback_dict = post_data['feedback'] rubric_scores_complete = request.POST.get('rubric_scores_complete', False) rubric_scores = request.POST.getlist('rubric_scores', []) is_submission_flagged = request.POST.get('submission_flagged', False) if isinstance(is_submission_flagged, basestring): is_submission_flagged = (is_submission_flagged.lower() == "true") status = GraderStatus.success confidence = 1.0 is_answer_unknown = request.POST.get('answer_unknown', False) if isinstance(is_answer_unknown, basestring): is_answer_unknown = (is_answer_unknown.lower() == "true") if is_answer_unknown: status = GraderStatus.failure confidence = 0.0 try: score = int(score) except ValueError: return util._error_response( "Expected integer score. Got {0}".format(score), _INTERFACE_VERSION) try: sub = Submission.objects.get(id=submission_id) except: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={ "msg": "Submission id {0} is not valid.".format(submission_id) }) success, error_message = grader_util.validate_rubric_scores( rubric_scores, rubric_scores_complete, sub) if not success: return util._error_response("grade_save_error", _INTERFACE_VERSION, data={"msg": error_message}) d = { 'submission_id': submission_id, 'score': score, 'feedback': feedback_dict, 'grader_id': grader_id, 'grader_type': 'PE', # Humans always succeed (if they grade at all)... 'status': status, # ...and they're always confident too. 'confidence': confidence, #And they don't make any errors 'errors': "", 'rubric_scores_complete': rubric_scores_complete, 'rubric_scores': rubric_scores, 'is_submission_flagged': is_submission_flagged, } #Currently not posting back to LMS. Only saving grader object, and letting controller decide when to post back. (success, header) = grader_util.create_and_handle_grader_object(d) if not success: return util._error_response( "There was a problem saving the grade. Contact support.", _INTERFACE_VERSION) #xqueue_session=util.xqueue_login() #error,msg = util.post_results_to_xqueue(xqueue_session,json.dumps(header),json.dumps(post_data)) util.log_connection_data() return util._success_response({'msg': "Posted to queue."}, _INTERFACE_VERSION)
def save_grade(request): """ Supports POST requests with the following arguments: course_id: int grader_id: int submission_id: int score: int feedback: string Returns json dict with keys version: int success: bool error: string, present if not success """ if request.method != "POST": return util._error_response("Request needs to be GET", _INTERFACE_VERSION) course_id = request.POST.get('course_id') grader_id = request.POST.get('grader_id') submission_id = request.POST.get('submission_id') score = request.POST.get('score') feedback = request.POST.get('feedback') skipped = request.POST.get('skipped') == "True" rubric_scores_complete = request.POST.get('rubric_scores_complete', False) rubric_scores = request.POST.getlist('rubric_scores', []) is_submission_flagged = request.POST.get('submission_flagged', False) if isinstance(is_submission_flagged, basestring): is_submission_flagged = is_submission_flagged.lower() == 'true' if ( # These have to be truthy not (course_id and grader_id and submission_id) or # These have to be non-None score is None or feedback is None): return util._error_response("required_parameter_missing", _INTERFACE_VERSION) if skipped: log.debug(submission_id) success, sub = staff_grading_util.set_instructor_grading_item_back_to_ml( submission_id) if not success: return util._error_response(sub, _INTERFACE_VERSION) return util._success_response({}, _INTERFACE_VERSION) try: score = int(score) except ValueError: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": "Expected integer score. Got {0}".format(score)}) try: sub = Submission.objects.get(id=submission_id) except: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={ "msg": "Submission id {0} is not valid.".format(submission_id) }) first_sub_for_location = Submission.objects.filter( location=sub.location).order_by('date_created')[0] rubric = first_sub_for_location.rubric rubric_success, parsed_rubric = rubric_functions.parse_rubric(rubric) if rubric_success: success, error_message = grader_util.validate_rubric_scores( rubric_scores, rubric_scores_complete, sub) if not success: return util._error_response("grade_save_error", _INTERFACE_VERSION, data={"msg": error_message}) d = { 'submission_id': submission_id, 'score': score, 'feedback': feedback, 'grader_id': grader_id, 'grader_type': 'IN', # Humans always succeed (if they grade at all)... 'status': GraderStatus.success, # ...and they're always confident too. 'confidence': 1.0, #And they don't make errors 'errors': "", 'rubric_scores_complete': rubric_scores_complete, 'rubric_scores': rubric_scores, 'is_submission_flagged': is_submission_flagged, } success, header = grader_util.create_and_handle_grader_object(d) if not success: return util._error_response("grade_save_error", _INTERFACE_VERSION, data={'msg': 'Internal error'}) util.log_connection_data() return util._success_response({}, _INTERFACE_VERSION)
def save_grade(request): """ Supports POST requests with the following arguments: location: string grader_id: int submission_id: int score: int feedback: string submission_key : string Returns json dict with keys version: int success: bool error: string, present if not success """ if request.method != "POST": raise Http404 post_data = request.POST.dict().copy() log.debug(post_data) for tag in ["location", "grader_id", "submission_id", "submission_key", "score", "feedback", "submission_flagged"]: if not tag in post_data: return util._error_response("Cannot find needed key {0} in request.".format(tag), _INTERFACE_VERSION) location = post_data["location"] grader_id = post_data["grader_id"] submission_id = post_data["submission_id"] # Submission key currently unused, but plan to use it for validation in the future. submission_key = post_data["submission_key"] score = post_data["score"] # This is done to ensure that response is properly formatted on the lms side. feedback_dict = post_data["feedback"] rubric_scores_complete = request.POST.get("rubric_scores_complete", False) rubric_scores = request.POST.getlist("rubric_scores", []) is_submission_flagged = request.POST.get("submission_flagged", False) if isinstance(is_submission_flagged, basestring): is_submission_flagged = is_submission_flagged.lower() == "true" status = GraderStatus.success confidence = 1.0 is_answer_unknown = request.POST.get("answer_unknown", False) if isinstance(is_answer_unknown, basestring): is_answer_unknown = is_answer_unknown.lower() == "true" if is_answer_unknown: status = GraderStatus.failure confidence = 0.0 try: score = int(score) except ValueError: return util._error_response("Expected integer score. Got {0}".format(score), _INTERFACE_VERSION) try: sub = Submission.objects.get(id=submission_id) except: return util._error_response( "grade_save_error", _INTERFACE_VERSION, data={"msg": "Submission id {0} is not valid.".format(submission_id)}, ) success, error_message = grader_util.validate_rubric_scores(rubric_scores, rubric_scores_complete, sub) if not success: return util._error_response("grade_save_error", _INTERFACE_VERSION, data={"msg": error_message}) d = { "submission_id": submission_id, "score": score, "feedback": feedback_dict, "grader_id": grader_id, "grader_type": "PE", # Humans always succeed (if they grade at all)... "status": status, # ...and they're always confident too. "confidence": confidence, # And they don't make any errors "errors": "", "rubric_scores_complete": rubric_scores_complete, "rubric_scores": rubric_scores, "is_submission_flagged": is_submission_flagged, } # Currently not posting back to LMS. Only saving grader object, and letting controller decide when to post back. (success, header) = grader_util.create_and_handle_grader_object(d) if not success: return util._error_response("There was a problem saving the grade. Contact support.", _INTERFACE_VERSION) # xqueue_session=util.xqueue_login() # error,msg = util.post_results_to_xqueue(xqueue_session,json.dumps(header),json.dumps(post_data)) util.log_connection_data() return util._success_response({"msg": "Posted to queue."}, _INTERFACE_VERSION)