diff --git a/lms/djangoapps/open_ended_grading/peer_grading_service.py b/lms/djangoapps/open_ended_grading/peer_grading_service.py index 1b78a32c5d..daccdd53af 100644 --- a/lms/djangoapps/open_ended_grading/peer_grading_service.py +++ b/lms/djangoapps/open_ended_grading/peer_grading_service.py @@ -88,18 +88,28 @@ def _err_response(msg): return HttpResponse(json.dumps({'success': False, 'error': msg}), mimetype="application/json") +def _check_required(request, required): + actual = set(request.POST.keys()) + missing = required - actual + if len(missing) > 0: + return False, "Missing required keys: {0}".format(', '.join(missing)) + else: + return True, "" + +def _check_post(request): + if request.method != 'POST': + raise Http404 + + def get_next_submission(request, course_id): """ TODO: fill in this documentation """ + _check_post(request) 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))) + success, message = _check_required(request, required) + if not success: + return _err_response(message) grader_id = request.user.id p = request.POST location = p['location'] @@ -119,3 +129,27 @@ def _get_next_submission(course_id, grader_id, location): return json.dumps({'success': False, 'error': 'Could not connect to grading service'}) + +def show_calibration_essay(request, course_id): + """ + TODO: fill in this documentation + """ + _check_post(request) + + required = set(['location']) + success, message = _check_required(request, required) + if not success: + return _err_response(message) + + grader_id = request.user.id + p = request.POST + location = p['location'] + try: + response = peer_grading_service().show_calibration_essay(location, grader_id) + return HttpResponse(response, mimetype="application/json") + 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 d4967aa0e9..6d41d47812 100644 --- a/lms/djangoapps/open_ended_grading/views.py +++ b/lms/djangoapps/open_ended_grading/views.py @@ -106,27 +106,6 @@ def peer_grading_problem(request, course_id, problem_location): ''' course = get_course_with_access(request.user, course_id, 'load') - # TODO: make sure that we show calibration or next submission correctly - # TODO: figure out if we want to make this page pure ajax or not - - problem_info_text = "" - error_text = "" - # if we are still in calibration - - # show a calibration essay - - # else, show an actual problem - try: - problem_info_text = peer_gs.get_next_submission(problem_location, request.user.id) - log.debug(problem_info_text) - problem_info = json.loads(problem_info_text) - success = problem_info['success'] - if 'error' in problem_info: - error_text = problem_info['error'] - except GradingServiceError: - success = False - - ajax_url = reverse('peer_grading', kwargs={'course_id': course_id}) if not ajax_url.endswith('/'): ajax_url += '/' @@ -134,11 +113,9 @@ def peer_grading_problem(request, course_id, problem_location): return render_to_response('peer_grading/peer_grading_problem.html', { 'view_html': '', 'course': course, + 'problem_location': problem_location, 'course_id': course_id, - 'success' : success, - 'problem_info': problem_info_text, 'ajax_url': ajax_url, - 'error_text': error_text, # Checked above 'staff_access': False, }) diff --git a/lms/static/coffee/src/peer_grading/peer_grading.coffee b/lms/static/coffee/src/peer_grading/peer_grading.coffee index 46f0206bbf..c20944252c 100644 --- a/lms/static/coffee/src/peer_grading/peer_grading.coffee +++ b/lms/static/coffee/src/peer_grading/peer_grading.coffee @@ -1,9 +1,10 @@ class PeerGrading constructor: (backend) -> - @problem_list = $('.problem-list') @error_container = $('.error-container') @error_container.toggle(not @error_container.is(':empty')) + @message_container = $('.message-container') + @message_container.toggle(not @message_container.is(':empty')) -backend = {} -$(document).ready(() -> new PeerGrading(backend)) +mock_backend = false +$(document).ready(() -> new PeerGrading(mock_backend)) diff --git a/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee b/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee index 461089b79c..5b7aef18c7 100644 --- a/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee +++ b/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee @@ -1,17 +1,96 @@ class PeerGradingProblemBackend constructor: (ajax_url, mock_backend) -> @mock_backend = mock_backend + @ajax_url = ajax_url + + post: (cmd, data, callback) -> + if @mock_backend + callback(@mock(cmd, data)) + else + # TODO: replace with postWithPrefix when that's loaded + $.post(@ajax_url + cmd, data, callback) + .error => callback({success: false, error: "Error occured while performing this operation"}) + + mock: (cmd, data) -> + if cmd == 'is_student_calibrated' + # change to test each version + response = + success: true + calibrated: false + else if cmd == 'show_calibration_essay' + response = + success: true + submission_id: 1 + submission_key: 'abcd' + student_response: 'I am a fake response' + prompt: 'Answer this question' + rubric: 'This is a rubric.' + max_score: 4 + + + return response + class PeerGradingProblem constructor: (backend) -> + @prompt_wrapper = $('.prompt-wrapper') + @backend = backend + + # ugly hack to prevent this code from trying to run on the + # general peer grading page + if( @prompt_wrapper.length == 0) + return + + # get the location of the problem + @location = $('.peer-grading').data('location') + + # get the other elements we want to fill in + @submission_container = $('.submission-container') + @prompt_container = $('.prompt-container') + @rubric_container = $('.rubric-container') + @error_container = $('.error-container') - @render_problem() - - render_problem: () -> - # do this when it makes sense - @error_container.toggle(not @error_container.is(':empty')) + @is_calibrated_check() -backend = {} + is_calibrated_check: () => + @backend.post('is_student_calibrated', {}, @calibration_check_callback) + + + fetch_calibration_essay: ()=> + @backend.post('show_calibration_essay', {location: @location}, @render_calibration) + + render_calibration: (response) => + if response.success + #TODO: fill this in + + @submission_container.html("
Here are a list of problems that need to be peer graded for this course.
% if success:+
+ +