diff --git a/lms/djangoapps/open_ended_grading/peer_grading_service.py b/lms/djangoapps/open_ended_grading/peer_grading_service.py index e3b2e823a7..b2b1fab5d3 100644 --- a/lms/djangoapps/open_ended_grading/peer_grading_service.py +++ b/lms/djangoapps/open_ended_grading/peer_grading_service.py @@ -36,5 +36,59 @@ class PeerGradingService(GradingService): 'submission_id' : submission_id, 'score' : score, 'feedback' : feedback, - 'submission_key', submission_key} + 'submission_key': submission_key} return self.post(self.save_grade_url, False, data) + + +def peer_grading_service(): + """ + Return a peer grading service instance--if settings.MOCK_PEER_GRADING is True, + returns a mock one, otherwise a real one. + + Caches the result, so changing the setting after the first call to this + function will have no effect. + """ + global _service + if _service is not None: + return _service + + _service = PeerGradingService(settings.PEER_GRADING_INTERFACE) + + return _service + +def _err_response(msg): + """ + Return a HttpResponse with a json dump with success=False, and the given error message. + """ + return HttpResponse(json.dumps({'success': False, 'error': msg}), + mimetype="application/json") + +def get_next_submission(request, course_id): + required = set(['location']) + if request.method != 'POST': + raise Http404 + actual = set(request.POST.keys()) + missing = required - actual + if len(missing) > 0: + return _err_response('Missing required keys {0}'.format( + ', '.join(missing))) + grader_id = request.user.id + p = request.POST + location = p['location'] + + return HttpResponse(_get_next(course_id, request.user.id, location), + mimetype="application/json") + +def _get_next_submission(course_id, grader_id, location): + """ + Implementation of get_next (also called from save_grade) -- returns a json string + """ + try: + return peer_grading_service().get_next_submission(location, grader_id) + except GradingServiceError: + log.exception("Error from grading service. server url: {0}" + .format(staff_grading_service().url)) + return json.dumps({'success': False, + 'error': 'Could not connect to grading service'}) + + diff --git a/lms/djangoapps/open_ended_grading/views.py b/lms/djangoapps/open_ended_grading/views.py index 9066f8323a..41eb0fbccf 100644 --- a/lms/djangoapps/open_ended_grading/views.py +++ b/lms/djangoapps/open_ended_grading/views.py @@ -48,10 +48,30 @@ def staff_grading(request, course_id): ajax_url += '/' return render_to_response('instructor/staff_grading.html', { - 'view_html': grading.get_html(), + 'view_html': '', 'course': course, 'course_id': course_id, 'ajax_url': ajax_url, # Checked above 'staff_access': True, }) + +def peer_grading(request, course_id): + ''' + Show a peer grading interface + ''' + course = get_course_with_access(request.user, course_id, 'load') + + ajax_url = reverse('peer_grading', kwargs={'course_id': course_id}) + if not ajax_url.endswith('/'): + ajax_url += '/' + + return render_to_response('peer_grading/peer_grading.html', { + 'view_html': '', + 'course': course, + 'course_id': course_id, + 'ajax_url': ajax_url, + # Checked above + 'staff_access': False, }) + + diff --git a/lms/envs/common.py b/lms/envs/common.py index 1cf22a6323..d18c82b754 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -418,6 +418,7 @@ main_vendor_js = [ discussion_js = sorted(glob2.glob(PROJECT_ROOT / 'static/coffee/src/discussion/**/*.coffee')) staff_grading_js = sorted(glob2.glob(PROJECT_ROOT / 'static/coffee/src/staff_grading/**/*.coffee')) +peer_grading_js = sorted(glob2.glob(PROJECT_ROOT / 'static/coffee/src/peer_grading/**/*.coffee')) # Load javascript from all of the available xmodules, and @@ -526,8 +527,11 @@ PIPELINE_JS = { 'staff_grading' : { 'source_filenames': [pth.replace(PROJECT_ROOT / 'static/', '') for pth in staff_grading_js], 'output_filename': 'js/staff_grading.js' + }, + 'peer_grading' : { + 'source_filenames': [pth.replace(PROJECT_ROOT / 'static/', '') for pth in peer_grading_js], + 'output_filename': 'js/peer_grading.js' } - } PIPELINE_DISABLE_WRAPPER = True diff --git a/lms/templates/instructor/staff_grading.html b/lms/templates/instructor/staff_grading.html index 33580c6267..085480a332 100644 --- a/lms/templates/instructor/staff_grading.html +++ b/lms/templates/instructor/staff_grading.html @@ -24,6 +24,8 @@
+ +