0001-templatetags-add-support-for-lazy-vars-to-string-fil.patch
tests/test_formdata.py | ||
---|---|---|
1616 | 1616 |
local_user.store() |
1617 | 1617 |
condition = Condition({'type': 'django', 'value': 'form_user_var_test'}) |
1618 | 1618 |
assert condition.evaluate() is False |
1619 | ||
1620 |
def test_string_filters(pub, variable_test_data): |
|
1621 |
tmpl = Template('{% with form_var_foo_foo|split:"a" as x %}{{x.0}}{% endwith %}', raises=True) |
|
1622 |
for mode in (None, 'lazy'): |
|
1623 |
context = pub.substitutions.get_context_variables(mode=mode) |
|
1624 |
assert tmpl.render(context) == 'b' |
|
1625 | ||
1626 |
tmpl = Template('{% if form_var_foo_foo|startswith:"b" %}test{% endif %}', raises=True) |
|
1627 |
for mode in (None, 'lazy'): |
|
1628 |
context = pub.substitutions.get_context_variables(mode=mode) |
|
1629 |
assert tmpl.render(context) == 'test' |
|
1630 | ||
1631 |
tmpl = Template('{% if form_var_foo_foo|startswith:form_var_term1 %}test{% endif %}', raises=True) |
|
1632 |
for mode in (None, 'lazy'): |
|
1633 |
context = pub.substitutions.get_context_variables(mode=mode) |
|
1634 |
assert tmpl.render(context) == '' |
wcs/qommon/templatetags/qommon.py | ||
---|---|---|
43 | 43 | |
44 | 44 |
@register.filter |
45 | 45 |
def startswith(string, substring): |
46 |
return string and string.startswith(substring)
|
|
46 |
return string and unicode(string).startswith(unicode(substring))
|
|
47 | 47 | |
48 | 48 |
@register.filter |
49 | 49 |
def split(string, separator=' '): |
50 |
return (string or '').split(separator) |
|
50 |
if not string: |
|
51 |
return [] |
|
52 |
return unicode(string).split(unicode(separator)) |
|
51 | 53 | |
52 | 54 |
@register.filter |
53 | 55 |
def parse_date(date_string): |
54 |
- |