Commit 9d4119b2 by Diana Huang

Merge pull request #1278 from MITx/vik/modify-rubric-input

Vik/modify rubric input
parents 79c8efcb be3d8cbb
......@@ -21,6 +21,8 @@ from .xml_module import XmlDescriptor
from xmodule.modulestore import Location
import self_assessment_module
import open_ended_module
from combined_open_ended_rubric import CombinedOpenEndedRubric
from .stringify import stringify_children
from mitxmako.shortcuts import render_to_string
......@@ -140,6 +142,12 @@ class CombinedOpenEndedModule(XModule):
# completion (doesn't matter if you self-assessed correct/incorrect).
self._max_score = int(self.metadata.get('max_score', MAX_SCORE))
rubric_renderer = CombinedOpenEndedRubric(True)
success, rubric_feedback = rubric_renderer.render_rubric(stringify_children(definition['rubric']))
if not success:
error_message="Could not parse rubric : {0}".format(definition['rubric'])
log.exception(error_message)
raise Exception
#Static data is passed to the child modules to render
self.static_data = {
'max_score': self._max_score,
......
......@@ -20,16 +20,25 @@ class CombinedOpenEndedRubric:
html: the html that corresponds to the xml given
'''
def render_rubric(self, rubric_xml):
success = False
try:
rubric_categories = self.extract_categories(rubric_xml)
html = render_to_string('open_ended_rubric.html',
{'categories' : rubric_categories,
'has_score': self.has_score,
'view_only': self.view_only})
success = True
except:
log.exception("Could not parse the rubric.")
try:
html = etree.tostring(rubric_xml, pretty_print=True)
return html
except:
log.exception("Rubric XML is a string, not an XML object : {0}".format(rubric_xml))
if isinstance(rubric_xml, basestring):
html = rubric_xml
else:
html = "Invalid rubric. Please contact course staff."
return success, html
def extract_categories(self, element):
'''
......@@ -43,6 +52,7 @@ class CombinedOpenEndedRubric:
{text: "Option 3 Name", points: 2]}]
'''
if isinstance(element, basestring):
element = etree.fromstring(element)
categories = []
for category in element:
......
......@@ -383,7 +383,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
feedback = self._convert_longform_feedback_to_html(response_items)
if response_items['rubric_scores_complete']==True:
rubric_renderer = CombinedOpenEndedRubric(True)
rubric_feedback = rubric_renderer.render_rubric(response_items['rubric_xml'])
success, rubric_feedback = rubric_renderer.render_rubric(response_items['rubric_xml'])
if not response_items['success']:
return system.render_template("open_ended_error.html",
......
......@@ -124,7 +124,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
rubric_renderer = CombinedOpenEndedRubric(True)
rubric_html = rubric_renderer.render_rubric(self.rubric)
success, rubric_html = rubric_renderer.render_rubric(self.rubric)
# we'll render it
context = {'rubric': rubric_html,
......
......@@ -262,9 +262,15 @@ def _get_next(course_id, grader_id, location):
try:
response = staff_grading_service().get_next(course_id, location, grader_id)
response_json = json.loads(response)
if response_json.has_key('rubric'):
rubric = response_json['rubric']
rubric_renderer = CombinedOpenEndedRubric(False)
rubric_html = rubric_renderer.render_rubric(rubric)
success, rubric_html = rubric_renderer.render_rubric(rubric)
if not success:
error_message = "Could not render rubric: {0}".format(rubric)
log.exception(error_message)
return json.dumps({'success': False,
'error': error_message})
response_json['rubric'] = rubric_html
return json.dumps(response_json)
except GradingServiceError:
......
......@@ -175,6 +175,7 @@ class StaffGrading
@feedback_area = $('.feedback-area')
@score_selection_container = $('.score-selection-container')
@grade_selection_container = $('.grade-selection-container')
@submit_button = $('.submit-button')
@action_button = $('.action-button')
......@@ -202,6 +203,7 @@ class StaffGrading
@num_graded = 0
@num_pending = 0
@score_lst = []
@grade = null
@problems = null
......@@ -216,10 +218,29 @@ class StaffGrading
setup_score_selection: =>
# first, get rid of all the old inputs, if any.
@grade_selection_container.html("""
<h3>Overall Score</h3>
<p>Choose an overall score for this submission.</p>
""")
# Now create new labels and inputs for each possible score.
for score in [0..@max_score]
id = 'score-' + score
label = """<label for="#{id}">#{score}</label>"""
input = """
<input type="radio" class="grade-selection" name="grade-selection" id="#{id}" value="#{score}"/>
""" # " fix broken parsing in emacs
@grade_selection_container.append(input + label)
$('.grade-selection').click => @graded_callback()
@score_selection_container.html(@rubric)
$('.score-selection').click => @graded_callback()
graded_callback: () =>
@grade = $("input[name='grade-selection']:checked").val()
if @grade == undefined
return
# check to see whether or not any categories have not been scored
num_categories = $('table.rubric tr').length
for i in [0..(num_categories-1)]
......@@ -230,8 +251,6 @@ class StaffGrading
@state = state_graded
@submit_button.show()
set_button_text: (text) =>
@action_button.attr('value', text)
......@@ -272,6 +291,7 @@ class StaffGrading
skip_and_get_next: () =>
data =
score: @grade
rubric_scores: @get_score_list()
feedback: @feedback_area.val()
submission_id: @submission_id
......@@ -285,8 +305,8 @@ class StaffGrading
submit_and_get_next: () ->
data =
score: @grade
rubric_scores: @get_score_list()
score: 0
feedback: @feedback_area.val()
submission_id: @submission_id
location: @location
......@@ -303,6 +323,8 @@ class StaffGrading
@rubric = response.rubric
@submission_id = response.submission_id
@feedback_area.val('')
@grade = null
@max_score = response.max_score
@ml_error_info=response.ml_error_info
@prompt_name = response.problem_name
@num_graded = response.num_graded
......@@ -322,9 +344,10 @@ class StaffGrading
@ml_error_info = null
@submission_id = null
@message = message
@grade = null
@max_score = 0
@state = state_no_data
render_view: () ->
# clear the problem list and breadcrumbs
@problem_list.html('')
......
......@@ -73,6 +73,8 @@
<div class="evaluation">
<p class="score-selection-container">
</p>
<p class="grade-selection-container">
</p>
<textarea name="feedback" placeholder="Feedback for student (optional)"
class="feedback-area" cols="70" ></textarea>
</div>
......
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