Commit 730cdd3b by Victor Shnayder

minor changes from pull request comments

- comments
- more info in log msg
- better error
parent 53580af9
...@@ -98,8 +98,19 @@ class StaffGradingService(object): ...@@ -98,8 +98,19 @@ class StaffGradingService(object):
def get_next(self, course_id, grader_id): def get_next(self, course_id, grader_id):
""" """
Get the next thing to grade. Returns json, or raises GradingServiceError Get the next thing to grade.
if there's a problem.
Args:
course_id: course id to get submission for
grader_id: who is grading this? The anonymous user_id of the grader.
Returns:
json string with the response from the service. (Deliberately not
writing out the fields here--see the docs on the staff_grading view
in the grading_controller repo)
Raises:
GradingServiceError: something went wrong with the connection.
""" """
op = lambda: self.session.get(self.get_next_url, op = lambda: self.session.get(self.get_next_url,
allow_redirects=False, allow_redirects=False,
...@@ -113,16 +124,18 @@ class StaffGradingService(object): ...@@ -113,16 +124,18 @@ class StaffGradingService(object):
return r.text return r.text
def save_grade(self, course_id, grader_id, submission_id, score, feedback): def save_grade(self, course_id, grader_id, submission_id, score, feedback):
""" """
Save a score and feedback for a submission. Save a score and feedback for a submission.
Returns json dict with keys Returns:
'success': bool json dict with keys
'error': error msg, if something went wrong. 'success': bool
'error': error msg, if something went wrong.
Raises GradingServiceError if there's a problem connecting. Raises:
GradingServiceError if there's a problem connecting.
""" """
try: try:
data = {'course_id': course_id, data = {'course_id': course_id,
...@@ -216,8 +229,10 @@ def _get_next(course_id, grader_id): ...@@ -216,8 +229,10 @@ def _get_next(course_id, grader_id):
try: try:
return grading_service().get_next(course_id, grader_id) return grading_service().get_next(course_id, grader_id)
except GradingServiceError: except GradingServiceError:
log.exception("Error from grading service") log.exception("Error from grading service. server url: {0}"
return json.dumps({'success': False, 'error': 'Could not connect to grading service'}) .format(grading_service().url))
return json.dumps({'success': False,
'error': 'Could not connect to grading service'})
@expect_json @expect_json
...@@ -239,10 +254,12 @@ def save_grade(request, course_id): ...@@ -239,10 +254,12 @@ def save_grade(request, course_id):
if request.method != 'POST': if request.method != 'POST':
raise Http404 raise Http404
required = ('score', 'feedback', 'submission_id') required = set('score', 'feedback', 'submission_id')
for k in required: actual = set(request.POST.keys())
if k not in request.POST.keys(): missing = required - actual
return _err_response('Missing required key {0}'.format(k)) if len(missing) != 0:
return _err_response('Missing required keys {0}'.format(
', '.join(missing)))
grader_id = request.user.id grader_id = request.user.id
p = request.POST p = request.POST
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment