0001-backoffice-compute-data_source-URL-if-it-s-a-templat.patch
tests/test_admin_pages.py | ||
---|---|---|
4994 | 4994 |
assert 'Preview' in resp.text |
4995 | 4995 |
assert 'foo' in resp.text |
4996 | 4996 | |
4997 |
# variadic url |
|
4998 |
data_source.data_source = {'type': 'json', 'value': '{{ site_url }}/foo/bar'} |
|
4999 |
data_source.store() |
|
5000 |
with HttpRequestsMocking() as http_requests: |
|
5001 |
resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id) |
|
5002 |
assert '<a href="http://example.net/foo/bar"' in resp.text |
|
5003 | ||
4997 | 5004 |
data_source.data_source = {'type': 'formula', 'value': '[str(x) for x in range(100)]'} |
4998 | 5005 |
data_source.store() |
4999 | 5006 |
resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id) |
wcs/data_sources.py | ||
---|---|---|
424 | 424 |
def humanized_cache_duration(self): |
425 | 425 |
return seconds2humanduration(int(self.cache_duration)) |
426 | 426 | |
427 |
def get_variadic_url(self): |
|
428 |
url = self.data_source.get('value').strip() |
|
429 |
if url and Template.is_template_string(url): |
|
430 |
vars = get_publisher().substitutions.get_context_variables(mode='lazy') |
|
431 |
url = get_variadic_url(url, vars) |
|
432 |
return url |
|
433 | ||
427 | 434 |
def is_used_in_formdef(self, formdef): |
428 | 435 |
from .fields import WidgetField |
429 | 436 |
for field in formdef.fields or []: |
wcs/templates/wcs/backoffice/data-sources.html | ||
---|---|---|
18 | 18 |
<ul> |
19 | 19 |
<li>{% trans "Type of source:" %} {{ datasource.type_label }}</li> |
20 | 20 |
{% if datasource.data_source.type == 'json' or datasource.data_source.type == 'jsonp' %} |
21 |
<li>{% trans "URL:" %} <a href="{{ datasource.data_source.value }}">{{ datasource.data_source.value }}</a></li>
|
|
21 |
<li>{% trans "URL:" %} <a href="{{ datasource.get_variadic_url }}">{{ datasource.data_source.value }}</a></li>
|
|
22 | 22 |
{% elif datasource.data_source.type == 'formula' %} |
23 | 23 |
<li>{% trans "Python Expression:" %} {{ datasource.data_source.value }}</li> |
24 | 24 |
{% endif %} |
25 |
- |