Use render_basic for StructBlocks (#3393)

Having a StructBlock rendered via a template was inconsistent with other
blocks, It also meant that overriding `render_basic()` in a child class
did nothing, again unlike all other blocks. Providing a `render_basic()`
is useful for block libraries, where a `render_basic()` provides a very
minimal implementation with the expectation that developers will provide
their own render method via a template.
pull/3394/head
Tim Heap 2017-02-21 21:39:29 +11:00 zatwierdzone przez Matt Westcott
rodzic 1e3548e671
commit 9c2f2aac0f
2 zmienionych plików z 5 dodań i 7 usunięć

Wyświetl plik

@ -1,6 +0,0 @@
<dl>
{% for key, val in self.items %}
<dt>{{ key }}</dt>
<dd>{{ val }}</dd>
{% endfor %}
</dl>

Wyświetl plik

@ -11,6 +11,7 @@ from django.template.loader import render_to_string
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property
from django.utils.html import format_html, format_html_join
from .base import Block, DeclarativeSubBlocksMetaclass
from .utils import js_dict
@ -175,9 +176,12 @@ class BaseStructBlock(Block):
return errors
def render_basic(self, value, context=None):
return format_html('<dl>\n{}\n</dl>', format_html_join(
'\n', ' <dt>{}</dt>\n <dd>{}</dd>', value.items()))
class Meta:
default = {}
template = "wagtailadmin/blocks/struct.html"
form_classname = 'struct-block'
form_template = 'wagtailadmin/block_forms/struct.html'
# No icon specified here, because that depends on the purpose that the