Projet

Général

Profil

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

Nicolas Roche, 27 septembre 2019 18:43

Télécharger (2,3 ko)

Voir les différences:

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

 combo/data/models.py | 13 +++++++++++--
 tests/test_pages.py  | 10 ++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)
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
                message = 'error in templated URL (%s): %s' % (match.group(2), e)
773
                logger = logging.getLogger(__name__)
774
                logger.warning(message)
775
                raise
770 776
            return '%s="%s"' % (attribute, url)
771
        text = re.sub(r'(href|src)="(.*?)"', sub_variadic_url, text)
777
        try:
778
            text = re.sub(r'(href|src)="(.*?)"', sub_variadic_url, text)
779
        except utils.TemplateError as e:
780
            text = "# can't render href|src templated attribut\n" + text
772 781

  
773 782
        if render_skeleton:
774 783
            request = context.get('request')
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 "# can't render href|src templated attribut" in response.text
299
-