def submit_to_ag(assignment, messages, submitter): if 'file_contents' not in messages: return email = submitter.email[0] data = { 'assignment': assignment.autograding_key, 'file_contents': messages['file_contents'], 'submitter': email } # Ensure user is enrolled. enrollment = ModelProxy.Participant.query( ModelProxy.Participant.course == assignment.course, ModelProxy.Participant.user == submitter.key).get() if not enrollment: raise BadValueError('User is not enrolled and cannot be autograded.') logging.info("Starting send to AG") headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(AUTOGRADER_URL+'/api/file/grade/continous', data=json.dumps(data), headers=headers) if r.status_code == requests.codes.ok: logging.info("Sent to Autograder") return {'status': "pending"} else: raise BadValueError('The autograder the rejected your request')
def autograde_final_subs(assignment, user, data): subm_ids = {} fsubs = list( ModelProxy.FinalSubmission.query( ModelProxy.FinalSubmission.assignment == obj.key)) for fsub in fsubs: subm_ids[fsub.submission.id()] = fsub.submission.get().backup.id() data = { 'subm_ids': subm_ids, 'assignment': obj.autograding_key, 'access_token': data['token'] } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(AUTOGRADER_URL + '/api/ok/grade/batch', data=json.dumps(data), headers=headers) if r.status_code == requests.codes.ok: # TODO: Contact user (via email) return { 'status_url': AUTOGRADER_URL + '/rq', 'length': str(len(subm_ids)) } else: raise BadValueError('The autograder the rejected your request')
def autograde_subms(assignment, user, data, subm_ids, priority="default"): ag_data = { 'subm_ids': subm_ids, 'assignment': assignment.autograding_key, 'access_token': data['token'], 'priority': priority, 'testing': 'testing' in data and data['testing'] } headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(AUTOGRADER_URL+'/api/ok/grade/batch', data=json.dumps(ag_data), headers=headers) if r.status_code == requests.codes.ok: # TODO: Contact staff (via email) return {'status_url': AUTOGRADER_URL+'/rq', 'length': str(len(subm_ids))} else: error_message = 'The autograder rejected your request. {}'.format(r.text) raise BadValueError(error_message)