0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Set the default cell renderer to "text" for handsontable and added an

"html" cell rendering option for those who need to override.
This commit is contained in:
Brad Busenius 2016-04-19 14:35:59 -05:00 committed by Matt Westcott
parent c8b42fa8cb
commit 0d301d1d7c
2 changed files with 20 additions and 4 deletions

View File

@ -54,7 +54,7 @@ class TableBlock(FieldBlock):
'stretchH': 'all',
'height': 108,
'language': language,
'renderer': 'html',
'renderer': 'text',
'autoColumnSize': False,
}
if table_options is not None:
@ -72,6 +72,9 @@ class TableBlock(FieldBlock):
def value_for_form(self, value):
return json.dumps(value)
def is_html_renderer(self):
return self.table_options['renderer'] == 'html'
def render(self, value):
template = getattr(self.meta, 'template', None)
if template and value:
@ -82,6 +85,7 @@ class TableBlock(FieldBlock):
self.TEMPLATE_VAR: value,
'table_header': table_header,
'first_col_is_header': first_col_is_header,
'html_renderer': self.is_html_renderer(),
'data': value['data'][1:] if table_header else value.get('data', [])
}
return render_to_string(template, context)

View File

@ -6,7 +6,11 @@
{% for column in table_header %}
<th>
{% if column.strip %}
{{ column.strip|linebreaksbr }}
{% if html_renderer %}
{{ column.strip|safe|linebreaksbr }}
{% else %}
{{ column.strip|linebreaksbr }}
{% endif %}
{% endif %}
</th>
{% endfor %}
@ -20,13 +24,21 @@
{% if first_col_is_header and forloop.first %}
<th>
{% if column.strip %}
{{ column.strip|linebreaksbr }}
{% if html_renderer %}
{{ column.strip|safe|linebreaksbr }}
{% else %}
{{ column.strip|linebreaksbr }}
{% endif %}
{% endif %}
</th>
{% else %}
<td>
{% if column.strip %}
{{ column.strip|linebreaksbr }}
{% if html_renderer %}
{{ column.strip|safe|linebreaksbr }}
{% else %}
{{ column.strip|linebreaksbr }}
{% endif %}
{% endif %}
</td>
{% endif %}