Commit 41486ac4 by Sven Marnach

Address Ned's review notes.

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