Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions problem_builder/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ class DashboardBlock(StudioEditableXBlockMixin, XBlock):
),
scope=Scope.content,
)
average_label = String(
average_labels = Dict(
display_name=_("Label for average value"),
default=_("Average"),
help=_("Label to be shown for calculated average"),
help=_(
"This settings allows overriding label for the calculated average per mentoring block. Must be in JSON "
"format. Examples: {examples_here}."
).format(
examples_here='{"2754b8afc03a439693b9887b6f1d9e36": "Avg.", "215028f7df3d4c68b14fb5fea4da7053": "Mean"}'
),
scope=Scope.content,
)
show_numbers = Boolean(
Expand All @@ -235,7 +239,7 @@ class DashboardBlock(StudioEditableXBlockMixin, XBlock):
)

editable_fields = (
'display_name', 'mentoring_ids', 'exclude_questions', 'average_label', 'show_numbers',
'display_name', 'mentoring_ids', 'exclude_questions', 'average_labels', 'show_numbers',
'color_rules', 'visual_rules', 'visual_title', 'visual_desc'
)
css_path = 'public/css/dashboard.css'
Expand Down Expand Up @@ -408,6 +412,7 @@ def student_view(self, context=None): # pylint: disable=unused-argument
if numeric_values:
average_value = sum(numeric_values) / len(numeric_values)
block['average'] = average_value
block['average_label'] = self.average_labels.get(mentoring_block.url_name, _("Average"))
block['has_average'] = True
block['average_color'] = self.color_for_value(average_value)
blocks.append(block)
Expand All @@ -434,7 +439,6 @@ def student_view(self, context=None): # pylint: disable=unused-argument
'blocks': blocks,
'display_name': self.display_name,
'visual_repr': visual_repr,
'average_label': self.average_label,
'show_numbers': self.show_numbers,
})

Expand Down Expand Up @@ -462,10 +466,33 @@ def add_error(msg):
for key, value in data.exclude_questions.iteritems():
if not isinstance(value, list):
add_error(
_(u"Exclude questions is malformed: value for key {key} is {value}, expected list of integers")
_(u"'Questions to be hidden' is malformed: value for key {key} is {value}, "
u"expected list of integers")
.format(key=key, value=value)
)

if key not in data.mentoring_ids:
add_error(
_(u"'Questions to be hidden' is malformed: mentoring url_name {url_name} "
u"is not added to Dashboard")
.format(url_name=key)
)

if data.average_labels:
for key, value in data.average_labels.iteritems():
if not isinstance(value, basestring):
add_error(
_(u"'Label for average value' is malformed: value for key {key} is {value}, expected string")
.format(key=key, value=value)
)

if key not in data.mentoring_ids:
add_error(
_(u"'Label for average value' is malformed: mentoring url_name {url_name} "
u"is not added to Dashboard")
.format(url_name=key)
)

if data.color_rules:
try:
self.parse_color_rules_str(data.color_rules, ignore_errors=False)
Expand Down
2 changes: 1 addition & 1 deletion problem_builder/templates/html/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2>{{display_name}}</h2>
{% endfor %}
{% if block.has_average %}
<tr class="avg-row">
<th class="desc">{{ average_label }}</th>
<th class="desc">{{ block.average_label }}</th>
<td class="value"
{% if block.average_color %} style="border-right-color: {{block.average_color}};"{% endif %}
{% if not show_numbers %}
Expand Down
12 changes: 8 additions & 4 deletions problem_builder/tests/integration/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ class TestDashboardBlock(SeleniumXBlockTest):
"""
SIMPLE_DASHBOARD = """<pb-dashboard mentoring_ids='["dummy-value"]'/>"""
ALTERNATIVE_DASHBOARD = dedent("""
<pb-dashboard mentoring_ids='["dummy-value"]' average_label="Avg." show_numbers="false"/>
<pb-dashboard mentoring_ids='["dummy-value"]' show_numbers="false"
average_labels='{"Step 1": "Avg.", "Step 2":"Mean", "Step 3":"Second Quartile"}'
/>
""")
HIDE_QUESTIONS_DASHBOARD = dedent("""
<pb-dashboard mentoring_ids='["dummy-value"]'
exclude_questions='{"Step 1": [2, 3], "Step 2":[3], "Step 3":[2]}'
exclude_questions='{"Step 1": [2, 3], "Step 2":[3], "Step 3":[2]}'
/>
""")
MALFORMED_HIDE_QUESTIONS_DASHBOARD = dedent("""
Expand Down Expand Up @@ -185,7 +187,9 @@ def test_dashboard_alternative(self):
steps = dashboard.find_elements_by_css_selector('tbody')
self.assertEqual(len(steps), 3)

for step in steps:
average_labels = ["Avg.", "Mean", "Second Quartile"]

for step_num, step in enumerate(steps):
mcq_rows = step.find_elements_by_css_selector('tr:not(.avg-row)')
self.assertTrue(2 <= len(mcq_rows) <= 3)
for mcq in mcq_rows:
Expand All @@ -194,7 +198,7 @@ def test_dashboard_alternative(self):
# Check the average:
avg_row = step.find_element_by_css_selector('tr.avg-row')
left_col = avg_row.find_element_by_css_selector('.desc')
self.assertEqual(left_col.text, "Avg.")
self.assertEqual(left_col.text, average_labels[step_num])
right_col = avg_row.find_element_by_css_selector('.value')
self.assertEqual(right_col.text, "")

Expand Down