Projet

Général

Profil

0001-utils-do-not-raise-on-Django-syntax-error-in-templat.patch

Nicolas Roche, 30 septembre 2019 15:32

Télécharger (1,97 ko)

Voir les différences:

Subject: [PATCH] utils: do not raise on Django syntax error in templated_url
 (#34518)

 combo/data/models.py |  6 +++++-
 tests/test_pages.py  | 10 ++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
combo/data/models.py
766 766
        def sub_variadic_url(match):
767 767
            attribute = match.group(1)
768 768
            url = match.group(2)
769
            url = utils.get_templated_url(url, context=context)
769
            try:
770
                url = utils.get_templated_url(url, context=context)
771
            except utils.TemplateError as e:
772
                logger = logging.getLogger(__name__)
773
                logger.warning('error in templated URL (%s): %s' % (match.group(2), e))
770 774
            return '%s="%s"' % (attribute, url)
771 775
        text = re.sub(r'(href|src)="(.*?)"', sub_variadic_url, text)
772 776

  
tests/test_pages.py
296 296
    response = app.get(page.get_online_url())
297 297
    assert '<meta name="description" content="page description" />' in response.text
298 298
    assert '<title>Combo - foo</title>' in response.text
299

  
300
def test_render_cell_having_href_template_error(app):
301
    page = Page(title=u'foo', slug='foo', template_name='standard-sidebar', order=0, description="page description")
302
    page.save()
303
    cell = TextCell(page=page,
304
                    text='<a href="{{e-service_url}}backoffice/...">link</a>',
305
                    order=0, placeholder='content')
306
    cell.save()
307
    response = app.get(page.get_online_url())
308
    assert "{{e-service_url}}backoffice/..." in response.text  # href not rendered 
299
-