Create the unique_id in the template (vs. model)

This commit is contained in:
David Larlet 2023-12-19 20:50:30 -05:00
parent c9b4b96c01
commit 7ff543e1d5
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
3 changed files with 33 additions and 29 deletions

View file

@ -194,10 +194,6 @@ class Map(NamedModel):
objects = models.Manager()
public = PublicManager()
@property
def unique_id(self):
return f"map_{self.pk}"
@property
def preview_settings(self):
from .views import _urls_for_js

View file

@ -13,14 +13,15 @@
{% endif %}
<tbody>
{% for map_inst in maps %}
{{ map_inst.preview_settings|json_script:map_inst.unique_id }}
{% with unique_id="map_"|addstr:map_inst.pk %}
{{ map_inst.preview_settings|json_script:unique_id }}
<tr>
<td>
<a href="{{ map_inst.get_absolute_url }}">{{ map_inst.name }}</a>
<button class="map-opener" data-map-id="{{ map_inst.unique_id }}">{% blocktrans %}Preview{% endblocktrans %}</button>
<button class="map-opener" data-map-id="{{ unique_id }}">{% blocktrans %}Preview{% endblocktrans %}</button>
<dialog>
<form method="dialog">
<div id="{{ map_inst.unique_id }}_target" class="map_fragment"></div>
<div id="{{ unique_id }}_target" class="map_fragment"></div>
<p class="close-dialog">
<button type="submit">Close</button>
</p>
@ -38,6 +39,7 @@
<a href="{% url 'map_download' map_inst.pk %}">{% translate "Download" %}</a>
</td>
</tr>
{% endwith %}
{% endfor %}
</tbody>
</table>

View file

@ -60,3 +60,9 @@ def ipdb(what):
ipdb.set_trace()
return ""
@register.filter
def addstr(arg1, arg2):
# Necessity: https://stackoverflow.com/a/23783666
return str(arg1) + str(arg2)