diff --git a/umap/models.py b/umap/models.py index e3e11e1c..c74e7c0e 100644 --- a/umap/models.py +++ b/umap/models.py @@ -1,4 +1,3 @@ -import json import os import time @@ -12,6 +11,7 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from .managers import PublicManager +from .utils import _urls_for_js # Did not find a clean way to do this in Django @@ -196,8 +196,6 @@ class Map(NamedModel): @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 diff --git a/umap/utils.py b/umap/utils.py index d7dfa6fb..2a51fe4e 100644 --- a/umap/utils.py +++ b/umap/utils.py @@ -1,9 +1,26 @@ import gzip import os +from django.conf import settings from django.urls import URLPattern, URLResolver, get_resolver +def _urls_for_js(urls=None): + """ + Return templated URLs prepared for javascript. + """ + if urls is None: + # prevent circular import + from .urls import i18n_urls, urlpatterns + + urls = [ + url.name for url in urlpatterns + i18n_urls if getattr(url, "name", None) + ] + urls = dict(zip(urls, [get_uri_template(url) for url in urls])) + urls.update(getattr(settings, "UMAP_EXTRA_URLS", {})) + return urls + + def get_uri_template(urlname, args=None, prefix=""): """ Utility function to return an URI Template from a named URL in django diff --git a/umap/views.py b/umap/views.py index d20b924a..08631cb0 100644 --- a/umap/views.py +++ b/umap/views.py @@ -390,22 +390,6 @@ ajax_proxy = AjaxProxy.as_view() # ############## # -def _urls_for_js(urls=None): - """ - Return templated URLs prepared for javascript. - """ - if urls is None: - # prevent circular import - from .urls import i18n_urls, urlpatterns - - urls = [ - url.name for url in urlpatterns + i18n_urls if getattr(url, "name", None) - ] - urls = dict(zip(urls, [get_uri_template(url) for url in urls])) - urls.update(getattr(settings, "UMAP_EXTRA_URLS", {})) - return urls - - def simple_json_response(**kwargs): return HttpResponse(json.dumps(kwargs), content_type="application/json")