misc: add support for not equal operator to lazy field vars (#30044)
This commit is contained in:
parent
7b30e43b4a
commit
f2f840cf36
|
@ -751,6 +751,9 @@ def test_lazy_templates(pub, variable_test_data):
|
|||
tmpl = Template('{{form_user_name_identifier_0}}')
|
||||
assert tmpl.render(context) == pub.user_class.select()[0].name_identifiers[0]
|
||||
|
||||
tmpl = Template('{% if form_user_email == "bar@localhost" %}HELLO{% endif %}')
|
||||
assert tmpl.render(context) == 'HELLO'
|
||||
|
||||
def test_lazy_ezt_templates(pub, variable_test_data):
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
tmpl = Template('[form_var_foo_foo]')
|
||||
|
@ -759,6 +762,33 @@ def test_lazy_ezt_templates(pub, variable_test_data):
|
|||
tmpl = Template('[is form_var_foo_foo "bar"]HELLO[else]BYE[end]')
|
||||
assert tmpl.render(context) == 'HELLO'
|
||||
|
||||
def test_lazy_formdata_fields(pub):
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foobar'
|
||||
formdef.url_name = 'foobar'
|
||||
formdef.fields = [
|
||||
fields.StringField(id='0', label='string', varname='string'),
|
||||
fields.ItemField(id='1', label='item', varname='item', items=['Foo', 'Bar'])
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'0': 'Foo', '1': 'Foo', '1_display': 'Foo'}
|
||||
formdata.store()
|
||||
|
||||
pub.substitutions.feed(formdata)
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
|
||||
tmpl = Template('{% if form_var_string == "Foo" %}HELLO{% endif %}')
|
||||
assert tmpl.render(context) == 'HELLO'
|
||||
tmpl = Template('{% if form_var_item == "Foo" %}HELLO{% endif %}')
|
||||
assert tmpl.render(context) == 'HELLO'
|
||||
|
||||
tmpl = Template('{% if form_var_string != "Foo" %}HELLO{% endif %}')
|
||||
assert tmpl.render(context) == ''
|
||||
tmpl = Template('{% if form_var_item != "Foo" %}HELLO{% endif %}')
|
||||
assert tmpl.render(context) == ''
|
||||
|
||||
def test_form_digest_date(pub):
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foobar'
|
||||
|
|
|
@ -369,6 +369,9 @@ class LazyFieldVar(object):
|
|||
def __eq__(self, other):
|
||||
return unicode(self) == unicode(other)
|
||||
|
||||
def __ne__(self, other):
|
||||
return unicode(self) != unicode(other)
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, int):
|
||||
return self.get_value()[key]
|
||||
|
|
Loading…
Reference in New Issue