add |form_asset_url filter to form asset url from commune sites (#51632)
This commit is contained in:
parent
8c8a3bd9ae
commit
99f47e5ef6
|
@ -21,6 +21,7 @@ import json
|
|||
import operator
|
||||
import random
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
from pyproj import Geod
|
||||
from requests import RequestException
|
||||
|
@ -885,3 +886,23 @@ def airquality_hack(cell, request):
|
|||
@register.simple_tag
|
||||
def get_known_tile_types():
|
||||
return list(settings.JSON_CELL_TYPES.keys())
|
||||
|
||||
|
||||
@register.filter
|
||||
def form_asset_url(url, is_safe=True):
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
form_slug = parsed.path.split('/')[1]
|
||||
# look for wcs service where the form is from, to get service prefix
|
||||
for service_key, service_dict in settings.KNOWN_SERVICES.get('wcs').items():
|
||||
if url.startswith(service_dict.get('url')):
|
||||
if service_key.startswith('_'):
|
||||
ou_prefix = service_key.rsplit('_', 1)[0] + '_'
|
||||
else:
|
||||
ou_prefix = ''
|
||||
break
|
||||
# get matching portal
|
||||
combo_service = settings.KNOWN_SERVICES.get('combo').get(ou_prefix + 'portal')
|
||||
if not combo_service:
|
||||
return ''
|
||||
# return well-known stable asset URL
|
||||
return urllib.parse.urljoin(combo_service.get('url'), '/assets/wcs:form:picture:eservices:%s' % form_slug)
|
||||
|
|
Loading…
Reference in New Issue