Commit cc409580 by Diana Huang

Handle scores if they exist in the xml

parent 90c39d51
...@@ -796,6 +796,7 @@ class RubricInput(InputTypeBase): ...@@ -796,6 +796,7 @@ class RubricInput(InputTypeBase):
submitted_msg = ("Feedback not yet available. Reload to check again. " submitted_msg = ("Feedback not yet available. Reload to check again. "
"Once the problem is graded, this message will be " "Once the problem is graded, this message will be "
"replaced with the grader's feedback.") "replaced with the grader's feedback.")
has_score = False
@classmethod @classmethod
def get_attributes(cls): def get_attributes(cls):
...@@ -811,14 +812,14 @@ class RubricInput(InputTypeBase): ...@@ -811,14 +812,14 @@ class RubricInput(InputTypeBase):
Add in the various bits and pieces that we need Add in the various bits and pieces that we need
""" """
return {'categories': self.categories, return {'categories': self.categories,
'view_only': False} 'view_only': False,
'has_score': self.has_score}
def setup(self): def setup(self):
# set the categories # set the categories
self.categories = self.extract_categories(self.xml) self.categories = self.extract_categories(self.xml)
@staticmethod def extract_categories(self, element):
def extract_categories(element):
''' '''
Contstruct a list of categories such that the structure looks like: Contstruct a list of categories such that the structure looks like:
[ { category: "Category 1 Name", [ { category: "Category 1 Name",
...@@ -835,12 +836,11 @@ class RubricInput(InputTypeBase): ...@@ -835,12 +836,11 @@ class RubricInput(InputTypeBase):
if category.tag != 'category': if category.tag != 'category':
raise Exception("[capa.inputtypes.extract_categories] Expected a <category> tag: got {0} instead".format(category.tag)) raise Exception("[capa.inputtypes.extract_categories] Expected a <category> tag: got {0} instead".format(category.tag))
else: else:
categories.append(RubricInput.extract_category(category)) categories.append(self.extract_category(category))
return categories return categories
@staticmethod def extract_category(self, category):
def extract_category(category):
''' '''
construct an individual category construct an individual category
{category: "Category 1 Name", {category: "Category 1 Name",
...@@ -851,6 +851,17 @@ class RubricInput(InputTypeBase): ...@@ -851,6 +851,17 @@ class RubricInput(InputTypeBase):
''' '''
descriptionxml = category[0] descriptionxml = category[0]
optionsxml = category[1:] optionsxml = category[1:]
scorexml = category[1]
score = None
if scorexml.tag == 'score':
score_text = scorexml.text
optionsxml = category[2:]
score = int(score_text)
self.has_score = True
# if we are missing the score tag and we are expecting one
elif self.has_score:
raise Exception("[inputtypes.extract_category] Category {0} is missing a score".format(descriptionxml.text))
# parse description # parse description
if descriptionxml.tag != 'description': if descriptionxml.tag != 'description':
...@@ -880,8 +891,10 @@ class RubricInput(InputTypeBase): ...@@ -880,8 +891,10 @@ class RubricInput(InputTypeBase):
cur_points = cur_points + 1 cur_points = cur_points + 1
else: else:
raise Exception("[extract_category]: missing points attribute. Cannot continue to auto-create points values after a points value is explicitly dfined.") raise Exception("[extract_category]: missing points attribute. Cannot continue to auto-create points values after a points value is explicitly dfined.")
selected = score == points
optiontext = option.text optiontext = option.text
options.append({'text': option.text, 'points': points}) options.append({'text': option.text, 'points': points, 'selected': selected})
# sort and check for duplicates # sort and check for duplicates
options = sorted(options, key=lambda option: option['points']) options = sorted(options, key=lambda option: option['points'])
......
<form class="rubric-template" id="inputtype_${id}"> <form class="rubric-template" id="inputtype_${id}">
<h3>Rubric</h3> <h3>Rubric</h3>
% if view_only: % if view_only and has_score:
<p>The highlighted selection matches how the grader feels you performed in each category.</p> <p>This is the rubric that was used to grade your submission.The highlighted selection matches how the grader feels you performed in each category.</p>
% elif view_only:
<p>Use the below rubric to rate this submission.</p>
% else: % else:
<p>Select the criteria you feel best represents this submission in each category.</p> <p>Select the criteria you feel best represents this submission in each category.</p>
% endif % endif
...@@ -14,10 +16,15 @@ ...@@ -14,10 +16,15 @@
<% option = category['options'][j] %> <% option = category['options'][j] %>
<td> <td>
% if view_only: % if view_only:
<div class="view-only"> ## if this is the selected rubric block, show it
${option['text']} % if option['selected']:
<div class="grade">[${option['points']} points]</div> <div class="view-only selected-grade">
</div> % else:
<div class="view-only">
% endif
${option['text']}
<div class="grade">[${option['points']} points]</div>
</div>
% else: % else:
<input type="radio" class="score-selection" name="score-selection-${i}" id="score-${i}-${j}" value="${option['points']}"/> <input type="radio" class="score-selection" name="score-selection-${i}" id="score-${i}-${j}" value="${option['points']}"/>
<label for="score-${i}-${j}">${option['text']}</label> <label for="score-${i}-${j}">${option['text']}</label>
......
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