summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas ROCHE <nroche@entrouvert.com>2019-09-25 16:27:30 (GMT)
committerNicolas ROCHE <nroche@entrouvert.com>2019-11-18 15:00:34 (GMT)
commit879be68be43bf849660c2fbd3cd9b7f50e724192 (patch)
tree932e93688a5bd1cb42931498ca7365c168cfc0c0
parent8a80889198630fa225cb5498ca38a9fdd5cd324e (diff)
downloadcombo-879be68be43bf849660c2fbd3cd9b7f50e724192.zip
combo-879be68be43bf849660c2fbd3cd9b7f50e724192.tar.gz
combo-879be68be43bf849660c2fbd3cd9b7f50e724192.tar.bz2
utils: do not raise on Django syntax error in templated_url (#34518)
-rw-r--r--combo/data/models.py6
-rw-r--r--tests/test_pages.py10
2 files changed, 15 insertions, 1 deletions
diff --git a/combo/data/models.py b/combo/data/models.py
index 4d086c8..da81df4 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -807,7 +807,11 @@ class TextCell(CellBase):
def sub_variadic_url(match):
attribute = match.group(1)
url = match.group(2)
- url = utils.get_templated_url(url, context=context)
+ try:
+ url = utils.get_templated_url(url, context=context)
+ except utils.TemplateError as e:
+ logger = logging.getLogger(__name__)
+ logger.warning('error in templated URL (%s): %s' % (url, e))
return '%s="%s"' % (attribute, url)
text = re.sub(r'(href|src)="(.*?)"', sub_variadic_url, text)
diff --git a/tests/test_pages.py b/tests/test_pages.py
index 77020e4..f44ee17 100644
--- a/tests/test_pages.py
+++ b/tests/test_pages.py
@@ -365,3 +365,13 @@ def test_render(app):
response = app.get(page.get_online_url())
assert '<meta name="description" content="page description" />' in response.text
assert '<title>Combo - foo</title>' in response.text
+
+def test_render_cell_having_href_template_error(app):
+ page = Page(title=u'foo', slug='foo', template_name='standard-sidebar', order=0, description="page description")
+ page.save()
+ cell = TextCell(page=page,
+ text='<a href="{{e-service_url}}backoffice/...">link</a>',
+ order=0, placeholder='content')
+ cell.save()
+ response = app.get(page.get_online_url())
+ assert "{{e-service_url}}backoffice/..." in response.text # href not rendered