Move _urls_for_js to utils.py (circular imports)
This commit is contained in:
parent
7ff543e1d5
commit
8d11815625
3 changed files with 18 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue