Projet

Général

Profil

0001-add-endswith-template-filter-43240.patch

Paul Marillonnet, 23 mai 2020 13:03

Télécharger (1,48 ko)

Voir les différences:

Subject: [PATCH] add 'endswith' template filter (#43240)

 tests/test_templates.py           | 7 +++++++
 wcs/qommon/templatetags/qommon.py | 5 +++++
 2 files changed, 12 insertions(+)
tests/test_templates.py
114 114
    assert tmpl.render({'foo': 'baz-bar'}) == ''
115 115

  
116 116

  
117
def test_endswith_templatetag():
118
    tmpl = Template('{% if foo|endswith:"bar" %}hello{% endif %}')
119
    assert tmpl.render() == ''
120
    assert tmpl.render({'foo': 'baz-bar'}) == 'hello'
121
    assert tmpl.render({'foo': 'bar-baz'}) == ''
122

  
123

  
117 124
def test_split_templatetag():
118 125
    tmpl = Template('{{ foo|split|last }}')
119 126
    assert tmpl.render() == ''
wcs/qommon/templatetags/qommon.py
52 52
    return string and force_text(string).startswith(force_text(substring))
53 53

  
54 54

  
55
@register.filter
56
def endswith(string, substring):
57
    return string and force_text(string).endswith(force_text(substring))
58

  
59

  
55 60
@register.filter
56 61
def split(string, separator=' '):
57 62
    if not string:
58
-