ref(blocks): do not render if map is not found
Parent
c6beb75a46
révision
fe55fce927
|
@ -52,4 +52,4 @@ class TestMapBlock:
|
|||
)
|
||||
|
||||
def test_render_unknown(self):
|
||||
assert self.render({'map': '100'}).strip() == ''
|
||||
assert self.render({'map': '100'}) == ''
|
||||
|
|
|
@ -43,6 +43,11 @@ class MapBlock(blocks.StructBlock):
|
|||
label = _("Map")
|
||||
template = 'wagtail_maps/map_block.html'
|
||||
|
||||
def render(self, value, context=None):
|
||||
if not value.get('map'):
|
||||
return ''
|
||||
return super().render(value, context=context)
|
||||
|
||||
def get_context(self, value, **kwargs):
|
||||
context = super().get_context(value, **kwargs)
|
||||
context['attrs'] = {}
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
{% if self.map %}
|
||||
<div class="map" data-map data-map-api-url="{% url "wagtail_maps:api:map-detail" self.map.pk %}"{% for name, value in attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %}></div>
|
||||
{% endif %}
|
||||
<div class="map" data-map data-map-api-url="{% url "wagtail_maps:api:map-detail" self.map.pk %}"{% for name, value in attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %}></div>
|
||||
|
|
Référencer dans un nouveau ticket