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()
|
objects = models.Manager()
|
||||||
public = PublicManager()
|
public = PublicManager()
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
return f"map_{self.pk}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preview_settings(self):
|
def preview_settings(self):
|
||||||
from .views import _urls_for_js
|
from .views import _urls_for_js
|
||||||
|
|
|
@ -13,14 +13,15 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for map_inst in maps %}
|
{% 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>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ map_inst.get_absolute_url }}">{{ map_inst.name }}</a>
|
<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>
|
<dialog>
|
||||||
<form method="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">
|
<p class="close-dialog">
|
||||||
<button type="submit">Close</button>
|
<button type="submit">Close</button>
|
||||||
</p>
|
</p>
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
<a href="{% url 'map_download' map_inst.pk %}">{% translate "Download" %}</a>
|
<a href="{% url 'map_download' map_inst.pk %}">{% translate "Download" %}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -60,3 +60,9 @@ def ipdb(what):
|
||||||
|
|
||||||
ipdb.set_trace()
|
ipdb.set_trace()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def addstr(arg1, arg2):
|
||||||
|
# Necessity: https://stackoverflow.com/a/23783666
|
||||||
|
return str(arg1) + str(arg2)
|
||||||
|
|
Loading…
Reference in a new issue