Create the unique_id in the template (vs. model)
This commit is contained in:
parent
c9b4b96c01
commit
7ff543e1d5
3 changed files with 33 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue