Set unique map id per page in map_list

This words around the issue where a map is displayed twice while
loading more maps in the home page because while loading maps some
have been updated
This commit is contained in:
Yohan Boniface 2019-04-09 11:47:02 +02:00
parent 7d9ae731c0
commit 95a16b2aaf
4 changed files with 8 additions and 6 deletions

View file

@ -1,5 +1,5 @@
{% load umap_tags %} {% load umap_tags %}
<div id="{{ prefix }}{{ map.pk }}" class="map_fragment"></div> <div id="{{ unique_id }}" class="map_fragment"></div>
<script type="text/javascript"> <script type="text/javascript">
new L.U.Map("{{ prefix }}{{ map.pk }}", {{ map_settings|notag|safe }}); new L.U.Map("{{ unique_id }}", {{ map_settings|notag|safe }});
</script> </script>

View file

@ -3,7 +3,7 @@
{% for map_inst in maps %} {% for map_inst in maps %}
<hr /> <hr />
<div class="col wide"> <div class="col wide">
{% map_fragment map_inst prefix=prefix %} {% map_fragment map_inst prefix=prefix page=request.GET.p %}
<div class="legend"><a href="{{ map_inst.get_absolute_url }}">{{ map_inst.name }}</a>{% if map_inst.owner %} <em>{% trans "by" %} <a href="{% url 'user_maps' map_inst.owner.username %}">{{ map_inst.owner }}</a></em>{% endif %}</div> <div class="legend"><a href="{{ map_inst.get_absolute_url }}">{{ map_inst.name }}</a>{% if map_inst.owner %} <em>{% trans "by" %} <a href="{% url 'user_maps' map_inst.owner.username %}">{{ map_inst.owner }}</a></em>{% endif %}</div>
</div> </div>
{% endfor %} {% endfor %}

View file

@ -8,7 +8,7 @@
<div class="wrapper"> <div class="wrapper">
<div class="map_list row"> <div class="map_list row">
{% if maps %} {% if maps %}
{% include "umap/map_list.html" with prefix='search_map_' %} {% include "umap/map_list.html" with prefix='search_map' %}
{% else %} {% else %}
{% trans "Not map found." %} {% trans "Not map found." %}
{% endif %} {% endif %}

View file

@ -50,11 +50,13 @@ def map_fragment(map_instance, **kwargs):
'slideshow': {} 'slideshow': {}
}) })
map_settings['properties'].update(kwargs) map_settings['properties'].update(kwargs)
prefix = kwargs.pop('prefix', None) or 'map_' prefix = kwargs.pop('prefix', None) or 'map'
page = kwargs.pop('page', None) or ''
unique_id = prefix + str(page) + "_" + str(map_instance.pk)
return { return {
"map_settings": json.dumps(map_settings), "map_settings": json.dumps(map_settings),
"map": map_instance, "map": map_instance,
"prefix": prefix "unique_id": unique_id
} }