misc: add .strip method to lazy variables (#44381)

This commit is contained in:
Frédéric Péters 2020-06-23 16:28:18 +02:00
parent 962a4bfe57
commit 445a3e9e64
2 changed files with 16 additions and 0 deletions

View File

@ -956,6 +956,18 @@ def test_lazy_map_variable(pub, variable_test_data):
assert WorkflowStatusItem.compute('{{ "1;2"|distance:form_var_map|floatformat }}', raises=True) == ''
def test_lazy_strip_method(pub, variable_test_data):
formdef = FormDef.select()[0]
formdata = formdef.data_class().select()[0]
formdata.data['0'] = ' bar '
for mode in (None, 'lazy'):
pub.substitutions.reset()
pub.substitutions.feed(formdef)
with pub.substitutions.temporary_feed(formdata, force_mode=mode):
assert WorkflowStatusItem.compute('{{ form_var_foo_foo }}', raises=True) == ' bar '
assert WorkflowStatusItem.compute('{{ form_var_foo_foo.strip }}', raises=True) == 'bar'
def test_lazy_conditions(pub, variable_test_data):
condition = Condition({'type': 'django', 'value': 'form_var_foo_foo == "bar"'})
assert condition.evaluate() is True

View File

@ -588,6 +588,10 @@ class LazyFieldVar(object):
def startswith(self, other):
return self.get_value().startswith(other)
def strip(self, *args):
warnings.warn('Deprecated use of .strip method', DeprecationWarning)
return self.get_value().strip(*args)
def __getstate__(self):
raise AssertionError('lazy cannot be pickled')