From a584f06bac1d03ca558491a40d9cadd9a5bf0ccf Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Mon, 19 Nov 2012 18:00:48 -0500 Subject: [PATCH] Add support for varying max_score. --- .../instructor/staff_grading_service.py | 26 +++++++--- lms/djangoapps/instructor/tests.py | 16 ++---- .../src/staff_grading/staff_grading.coffee | 50 +++++++++++++------ .../src/staff_grading/test_grading.html | 6 +-- 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/lms/djangoapps/instructor/staff_grading_service.py b/lms/djangoapps/instructor/staff_grading_service.py index 2a2a7a3552..11f6189547 100644 --- a/lms/djangoapps/instructor/staff_grading_service.py +++ b/lms/djangoapps/instructor/staff_grading_service.py @@ -34,9 +34,10 @@ class MockStaffGradingService(object): return json.dumps({'success': True, 'submission_id': self.cnt, 'submission': 'Test submission {cnt}'.format(cnt=self.cnt), + 'max_score': 2 + self.cnt % 3, 'rubric': 'A rubric'}) - def save_grade(self, course_id, submission_id, score, feedback): + def save_grade(self, course_id, grader_id, submission_id, score, feedback): return self.get_next(course_id) @@ -62,16 +63,23 @@ class StaffGradingService(object): return r.text - def save_grade(self, course_id, submission_id, score, feedback): + def save_grade(self, course_id, grader_id, submission_id, score, feedback): """ - Save a grade. + Save a score and feedback for a submission. - TODO: what is data? + Returns json dict with keys + 'success': bool + 'error': error msg, if something went wrong. - Returns json, or raises GradingServiceError if there's a problem. + Raises GradingServiceError if there's a problem connecting. """ try: - r = self.session.get(self.url + 'save_grade') + data = {'course_id': course_id, + 'submission_id': submission_id, + 'score': score, + 'feedback': feedback, + 'grader_id': grader} + r = self.session.post(self.url + 'save_grade') except requests.exceptions.ConnectionError as err: # reraise as promised GradingServiceError, but preserve stacktrace. raise GradingServiceError, str(err), sys.exc_info()[2] @@ -163,7 +171,11 @@ def save_grade(request, course_id): p = request.POST try: - result_json = _service.save_grade(course_id, p['submission_id'], p['score'], p['feedback']) + result_json = _service.save_grade(course_id, + request.user.id, + p['submission_id'], + p['score'], + p['feedback']) except GradingServiceError: log.exception("Error saving grade") return _err_response('Could not connect to grading service') diff --git a/lms/djangoapps/instructor/tests.py b/lms/djangoapps/instructor/tests.py index 28a56ad9de..87be93128c 100644 --- a/lms/djangoapps/instructor/tests.py +++ b/lms/djangoapps/instructor/tests.py @@ -112,15 +112,9 @@ class TestInstructorDashboardForumAdmin(ct.PageLoader): xmodule.modulestore.django._MODULESTORES = {} courses = modulestore().get_courses() -<<<<<<< HEAD - self.full = modulestore().get_course("edX/full/6.002_Spring_2012") - self.toy = modulestore().get_course("edX/toy/2012_Fall") -======= - self.course_id = "edX/toy/2012_Fall" self.toy = modulestore().get_course(self.course_id) ->>>>>>> Refactor testing code, hook up frontend. # Create two accounts self.student = 'view@test.com' @@ -236,9 +230,6 @@ class TestStaffGradingService(ct.PageLoader): access control and error handling logic -- all the actual work is on the backend. ''' - - - def setUp(self): xmodule.modulestore.django._MODULESTORES = {} @@ -265,8 +256,6 @@ class TestStaffGradingService(ct.PageLoader): self.check_for_get_code(404, url) self.check_for_post_code(404, url) -<<<<<<< HEAD -======= @patch.object(staff_grading_service, '_service', _mock_service) def test_get_next(self): @@ -286,11 +275,12 @@ class TestStaffGradingService(ct.PageLoader): url = reverse('staff_grading_save_grade', kwargs={'course_id': self.course_id}) - data = {'score': '12', 'feedback': 'great!', 'submission_id': '123'} + data = {'score': '12', + 'feedback': 'great!', + 'submission_id': '123'} r = self.check_for_post_code(200, url, data) d = json.loads(r.content) self.assertTrue(d['success'], str(d)) self.assertEquals(d['submission_id'], _mock_service.cnt) ->>>>>>> Refactor testing code, hook up frontend. diff --git a/lms/static/coffee/src/staff_grading/staff_grading.coffee b/lms/static/coffee/src/staff_grading/staff_grading.coffee index 7440277d98..b36b9e33e7 100644 --- a/lms/static/coffee/src/staff_grading/staff_grading.coffee +++ b/lms/static/coffee/src/staff_grading/staff_grading.coffee @@ -18,21 +18,19 @@ class StaffGradingBackend mock: (cmd, data) -> # Return a mock response to cmd and data - @mock_cnt++ if cmd == 'get_next' + @mock_cnt++ response = success: true submission: 'submission! ' + @mock_cnt rubric: 'A rubric! ' + @mock_cnt submission_id: @mock_cnt + max_score: 2 + @mock_cnt % 3 else if cmd == 'save_grade' console.log("eval: #{data.score} pts, Feedback: #{data.feedback}") response = - success: true - submission: 'another submission! ' + @mock_cnt - rubric: 'A rubric!' + @mock_cnt - submission_id: @mock_cnt + @mock('get_next', {}) else response = success: false @@ -72,6 +70,7 @@ class StaffGrading @submission_wrapper = $('.submission-wrapper') @rubric_wrapper = $('.rubric-wrapper') @feedback_area = $('.feedback-area') + @score_selection_container = $('.score-selection-container') @submit_button = $('.submit-button') # model state @@ -81,15 +80,12 @@ class StaffGrading @rubric = '' @error_msg = '' @message = '' + @max_score = 0 @score = null # action handlers @submit_button.click @submit - # TODO: hook up an event to the input changing, which updates - # @score (instead of the individual hacks) - $('#correct-radio').click @graded_callback - $('#incorrect-radio').click @graded_callback # render intial state @render_view() @@ -98,6 +94,24 @@ class StaffGrading @get_next_submission() + setup_score_selection: => + # first, get rid of all the old inputs, if any. + @score_selection_container.html('') + + # Now create new labels and inputs for each possible score. + for score in [1..@max_score] + id = 'score-' + score + label = """""" + + input = """ + + """ + @score_selection_container.append(label + input) + + # And now hook up an event handler again + $("input[name='score-selection']").change @graded_callback + + set_button_text: (text) => @submit_button.attr('value', text) @@ -113,7 +127,7 @@ class StaffGrading if response.success if response.submission - @data_loaded(response.submission, response.rubric, response.submission_id) + @data_loaded(response.submission, response.rubric, response.submission_id, response.max_score) else @no_more(response.message) else @@ -136,11 +150,12 @@ class StaffGrading @error_msg = msg @state = state_error - data_loaded: (submission, rubric, submission_id) -> + data_loaded: (submission, rubric, submission_id, max_score) -> @submission = submission @rubric = rubric @submission_id = submission_id @feedback_area.val('') + @max_score = max_score @score = null @state = state_grading @@ -149,6 +164,8 @@ class StaffGrading @rubric = null @submission_id = null @message = message + @score = null + @max_score = 0 @state = state_no_data render_view: () -> @@ -157,6 +174,9 @@ class StaffGrading show_submit_button = true @message_container.html(@message) + if @backend.mock_backend + @message_container.append("

NOTE: Mocking backend.

") + @error_container.html(@error_msg) if @state == state_error @@ -170,10 +190,8 @@ class StaffGrading # no submit button until user picks grade. show_submit_button = false - # TODO: clean up with proper input-related logic - $('#correct-radio')[0].checked = false - $('#incorrect-radio')[0].checked = false - + @setup_score_selection() + else if @state == state_graded show_grading_elements = true @set_button_text('Submit') @@ -204,7 +222,7 @@ class StaffGrading # for now, just create an instance and load it... -mock_backend = false +mock_backend = true ajax_url = $('.staff-grading').data('ajax_url') backend = new StaffGradingBackend(ajax_url, mock_backend) diff --git a/lms/static/coffee/src/staff_grading/test_grading.html b/lms/static/coffee/src/staff_grading/test_grading.html index 8a1cde1fd4..9b84d0703b 100644 --- a/lms/static/coffee/src/staff_grading/test_grading.html +++ b/lms/static/coffee/src/staff_grading/test_grading.html @@ -30,11 +30,7 @@
-

- - - - +