Commit 41486ac4 by Sven Marnach

Address Ned's review notes.

parent 4de83756
......@@ -28,7 +28,8 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
)
content = String(
display_name='Table definition',
help='The definition of the table in Python-like syntax.',
help='The definition of the table in Python-like syntax. Note that changing the table '
'definition of a live problem will invalidate all student answers.',
scope=Scope.content,
multiline_editor=True,
resettable_editor=False,
......@@ -53,8 +54,8 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
column_widths = String(
display_name='Column widths',
help='Set the width of the columns in pixels. The value should be a Python-like list of '
'numerical values. The total width of the table should not be more than 800. No value '
'will result in equal-width columns with a total width of 800 pixels.',
'numerical values. The total width of the table should not be more than 800. Omitting '
'this value will result in equal-width columns with a total width of 800 pixels.',
scope=Scope.content,
resettable_editor=False,
)
......@@ -68,7 +69,7 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
)
default_tolerance = Float(
display_name='Default tolerance',
help='The tolerance in pecent that is used for numerical response cells you did not '
help='The tolerance in percent that is used for numerical response cells you did not '
'specify an explicit tolerance for.',
scope=Scope.content,
default=1.0,
......@@ -148,7 +149,7 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
self.response_cells = {}
for row, height in zip(self.tbody, self._row_heights[1:]):
row['height'] = height
if row['index'] & 1:
if row['index'] % 2:
row['class'] = 'even'
else:
row['class'] = 'odd'
......
......@@ -13,6 +13,8 @@ import decimal
class Cell(object):
"""Abstract base class for all cells."""
is_static = False
def __eq__(self, other):
"""Test for equality based on type and attribute values."""
return type(self) is type(other) and vars(self) == vars(other)
......@@ -30,7 +32,6 @@ class StaticCell(Cell):
class NumericCell(Cell):
"""A numeric response cell."""
is_static = False
placeholder = 'numeric response'
def __init__(self, answer, tolerance=None,
......@@ -65,7 +66,6 @@ class NumericCell(Cell):
class StringCell(Cell):
"""A string response cell."""
is_static = False
placeholder = 'text response'
def __init__(self, answer):
......@@ -74,4 +74,4 @@ class StringCell(Cell):
def check_response(self, student_response):
"""Return a Boolean value indicating whether the student response is correct."""
return student_response == self.answer
return student_response.strip() == self.answer.strip()
......@@ -81,7 +81,7 @@ def _parse_response_cell(cell_node):
raise ParseError('invalid cell input type: {}'.format(cell_type))
try:
return cell_class(**kwargs)
except TypeError as exc:
except Exception as exc:
raise ParseError(exc.message)
......
......@@ -32,4 +32,7 @@ class CellTest(unittest.TestCase):
def test_string_cell(self):
cell = StringCell('OpenCraft')
self.assertTrue(cell.check_response('OpenCraft'))
self.assertTrue(cell.check_response(' OpenCraft \t\r\n'))
self.assertFalse(cell.check_response('giraffe'))
cell = StringCell('ÖpenCräft')
self.assertTrue(cell.check_response('ÖpenCräft'))
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