diff --git a/umap/models.py b/umap/models.py index 71f68144..7bf8494f 100644 --- a/umap/models.py +++ b/umap/models.py @@ -1,3 +1,4 @@ +import json import os import time @@ -193,6 +194,40 @@ 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 + + layers = self.datalayer_set.all() + datalayer_data = [c.metadata() for c in layers] + map_settings = self.settings + if "properties" not in map_settings: + map_settings["properties"] = {} + map_settings["properties"].update( + { + "tilelayers": [TileLayer.get_default().json], + "datalayers": datalayer_data, + "urls": _urls_for_js(), + "STATIC_URL": settings.STATIC_URL, + "editMode": "disabled", + "hash": False, + "attributionControl": False, + "scrollWheelZoom": False, + "umapAttributionControl": False, + "noControl": True, + "umap_id": self.pk, + "onLoadPanel": "none", + "captionBar": False, + "default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, + "slideshow": {}, + } + ) + return map_settings + def get_absolute_url(self): return reverse("map", kwargs={"slug": self.slug or "map", "map_id": self.pk}) diff --git a/umap/templates/umap/map_table.html b/umap/templates/umap/map_table.html index e4df76b7..d5721d15 100644 --- a/umap/templates/umap/map_table.html +++ b/umap/templates/umap/map_table.html @@ -1,9 +1,8 @@ -{% load umap_tags umap_tags i18n %} +{% load umap_tags i18n %} {% if not is_ajax %} - @@ -14,10 +13,19 @@ {% endif %} {% for map_inst in maps %} + {{ map_inst.preview_settings|json_script:map_inst.unique_id }} - @@ -39,3 +47,33 @@ class="button more_button neutral">{% trans "More" %} {% endif %} + + + + diff --git a/umap/templatetags/umap_tags.py b/umap/templatetags/umap_tags.py index 349e426e..70728ffa 100644 --- a/umap/templatetags/umap_tags.py +++ b/umap/templatetags/umap_tags.py @@ -4,9 +4,6 @@ from copy import copy from django import template from django.conf import settings -from ..models import DataLayer, TileLayer -from ..views import _urls_for_js - register = template.Library() @@ -22,30 +19,7 @@ def umap_js(locale=None): @register.inclusion_tag("umap/map_fragment.html") def map_fragment(map_instance, **kwargs): - layers = DataLayer.objects.filter(map=map_instance) - datalayer_data = [c.metadata() for c in layers] - map_settings = map_instance.settings - if "properties" not in map_settings: - map_settings["properties"] = {} - map_settings["properties"].update( - { - "tilelayers": [TileLayer.get_default().json], - "datalayers": datalayer_data, - "urls": _urls_for_js(), - "STATIC_URL": settings.STATIC_URL, - "editMode": "disabled", - "hash": False, - "attributionControl": False, - "scrollWheelZoom": False, - "umapAttributionControl": False, - "noControl": True, - "umap_id": map_instance.pk, - "onLoadPanel": "none", - "captionBar": False, - "default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, - "slideshow": {}, - } - ) + map_settings = map_instance.preview_settings map_settings["properties"].update(kwargs) prefix = kwargs.pop("prefix", None) or "map" page = kwargs.pop("page", None) or ""
{% blocktrans %}Map{% endblocktrans %} {% blocktrans %}Name{% endblocktrans %} {% blocktrans %}Who can see / edit{% endblocktrans %} {% blocktrans %}Last save{% endblocktrans %}
{% map_fragment map_inst prefix=prefix page=request.GET.p %} {{ map_inst.name }} + + +
+
+

+ +

+
+
{{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }} {{ map_inst.modified_at }}