cliss21
/
wagtail-maps
Archivé
5
0
Bifurcation 0

ref(blocks): do not render if map is not found

main
Jérôme Lebleu 2021-10-12 18:20:50 +02:00
Parent c6beb75a46
révision fe55fce927
3 fichiers modifiés avec 7 ajouts et 4 suppressions

Voir le fichier

@ -52,4 +52,4 @@ class TestMapBlock:
)
def test_render_unknown(self):
assert self.render({'map': '100'}).strip() == ''
assert self.render({'map': '100'}) == ''

Voir le fichier

@ -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'] = {}

Voir le fichier

@ -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>