Commit 5d2bc7df by Sven Marnach

Validate the number of entries in column widths and row heights.

parent 072ab3ed
...@@ -248,16 +248,29 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -248,16 +248,29 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
"""Add a validation error.""" """Add a validation error."""
validation.add(ValidationMessage(ValidationMessage.ERROR, msg)) validation.add(ValidationMessage(ValidationMessage.ERROR, msg))
try: try:
parse_table(data.table_definition) thead, tbody = parse_table(data.table_definition)
except ParseError as exc: except ParseError as exc:
add_error('Problem with table definition: ' + exc.message) add_error('Problem with table definition: ' + exc.message)
thead = tbody = None
if data.column_widths: if data.column_widths:
try: try:
parse_number_list(data.column_widths) column_widths = parse_number_list(data.column_widths)
except ParseError as exc: except ParseError as exc:
add_error('Problem with column widths: ' + exc.message) add_error('Problem with column widths: ' + exc.message)
else:
if thead is not None and len(column_widths) != len(thead):
add_error(
'The number of list entries in the Column widths field must match the '
'number of columns in the table.'
)
if data.row_heights: if data.row_heights:
try: try:
parse_number_list(data.row_heights) row_heights = parse_number_list(data.row_heights)
except ParseError as exc: except ParseError as exc:
add_error('Problem with row heights: ' + exc.message) add_error('Problem with row heights: ' + exc.message)
else:
if tbody is not None and len(row_heights) != len(tbody) + 1:
add_error(
'The number of list entries in the Row heights field must match the number '
'of rows in the table.'
)
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