backoffice: compute data_source URL if it's a template (#13902)
This commit is contained in:
parent
e3c5b3be9b
commit
a56ae27bcb
|
@ -4994,6 +4994,13 @@ def test_data_sources_view(pub):
|
|||
assert 'Preview' in resp.text
|
||||
assert 'foo' in resp.text
|
||||
|
||||
# variadic url
|
||||
data_source.data_source = {'type': 'json', 'value': '{{ site_url }}/foo/bar'}
|
||||
data_source.store()
|
||||
with HttpRequestsMocking() as http_requests:
|
||||
resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
|
||||
assert '<a href="http://example.net/foo/bar"' in resp.text
|
||||
|
||||
data_source.data_source = {'type': 'formula', 'value': '[str(x) for x in range(100)]'}
|
||||
data_source.store()
|
||||
resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
|
||||
|
|
|
@ -424,6 +424,13 @@ class NamedDataSource(XmlStorableObject):
|
|||
def humanized_cache_duration(self):
|
||||
return seconds2humanduration(int(self.cache_duration))
|
||||
|
||||
def get_variadic_url(self):
|
||||
url = self.data_source.get('value').strip()
|
||||
if url and Template.is_template_string(url):
|
||||
vars = get_publisher().substitutions.get_context_variables(mode='lazy')
|
||||
url = get_variadic_url(url, vars)
|
||||
return url
|
||||
|
||||
def is_used_in_formdef(self, formdef):
|
||||
from .fields import WidgetField
|
||||
for field in formdef.fields or []:
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<ul>
|
||||
<li>{% trans "Type of source:" %} {{ datasource.type_label }}</li>
|
||||
{% if datasource.data_source.type == 'json' or datasource.data_source.type == 'jsonp' %}
|
||||
<li>{% trans "URL:" %} <a href="{{ datasource.data_source.value }}">{{ datasource.data_source.value }}</a></li>
|
||||
<li>{% trans "URL:" %} <a href="{{ datasource.get_variadic_url }}">{{ datasource.data_source.value }}</a></li>
|
||||
{% elif datasource.data_source.type == 'formula' %}
|
||||
<li>{% trans "Python Expression:" %} {{ datasource.data_source.value }}</li>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue