From 7ff543e1d581009869ac642e49487abbd9e64f96 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Tue, 19 Dec 2023 20:50:30 -0500 Subject: [PATCH] Create the unique_id in the template (vs. model) --- umap/models.py | 4 --- umap/templates/umap/map_table.html | 52 ++++++++++++++++-------------- umap/templatetags/umap_tags.py | 6 ++++ 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/umap/models.py b/umap/models.py index 7bf8494f..e3e11e1c 100644 --- a/umap/models.py +++ b/umap/models.py @@ -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 diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index d5721d15..6da94810 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -13,31 +13,33 @@ {% endif %} {% for map_inst in maps %} - {{ map_inst.preview_settings|json_script:map_inst.unique_id }} - - - {{ map_inst.name }} - - -
-
-

- -

-
-
- - {{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }} - {{ map_inst.modified_at }} - - {{ map_inst.owner }} - - - {% translate "Share" %} | - {% translate "Edit" %} | - {% translate "Download" %} - - + {% with unique_id="map_"|addstr:map_inst.pk %} + {{ map_inst.preview_settings|json_script:unique_id }} + + + {{ map_inst.name }} + + +
+
+

+ +

+
+
+ + {{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }} + {{ map_inst.modified_at }} + + {{ map_inst.owner }} + + + {% translate "Share" %} | + {% translate "Edit" %} | + {% translate "Download" %} + + + {% endwith %} {% endfor %} diff --git a/umap/templatetags/umap_tags.py b/umap/templatetags/umap_tags.py index 70728ffa..2349c579 100644 --- a/umap/templatetags/umap_tags.py +++ b/umap/templatetags/umap_tags.py @@ -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)