templatetags: adapt |length and |length_is for lazy variables (#49383)
This commit is contained in:
parent
93ef308b1b
commit
45580748ae
|
@ -1250,6 +1250,25 @@ def test_lazy_variables_missing(pub, variable_test_data):
|
|||
assert context['form_var_foo_foo_xxx'] == 'bar'
|
||||
|
||||
|
||||
def test_lazy_variables_length(pub, variable_test_data):
|
||||
formdef = FormDef.select()[0]
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.data = {
|
||||
'0': 'bar',
|
||||
'6': '3',
|
||||
}
|
||||
pub.substitutions.reset()
|
||||
pub.substitutions.feed(formdef)
|
||||
pub.substitutions.feed(formdata)
|
||||
for mode in (None, 'lazy'):
|
||||
pub.substitutions.reset()
|
||||
pub.substitutions.feed(formdata)
|
||||
assert WorkflowStatusItem.compute('{{ form_var_foo_foo|length }}') == '3'
|
||||
assert WorkflowStatusItem.compute('{% if form_var_foo_foo|length_is:3 %}ok{% endif %}') == 'ok'
|
||||
assert WorkflowStatusItem.compute('{% if form_var_foo_foo|length_is:form_var_foo_foo_baz_baz %}ok{% endif %}') == 'ok'
|
||||
|
||||
|
||||
def test_lazy_map_variable(pub, variable_test_data):
|
||||
formdef = FormDef.select()[0]
|
||||
formdata = formdef.data_class().select()[0]
|
||||
|
|
|
@ -665,6 +665,13 @@ class LazyFieldVar(object):
|
|||
def __mul__(self, other):
|
||||
return self.get_value().__mul__(other)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.get_value())
|
||||
|
||||
def __int__(self):
|
||||
return int(self.get_value())
|
||||
|
||||
|
||||
def startswith(self, other):
|
||||
return self.get_value().startswith(other)
|
||||
|
||||
|
|
Loading…
Reference in New Issue