misc: add rich comparison methods to lazy field var (#68723) #335
|
@ -2284,6 +2284,20 @@ def test_lazy_conditions_in(pub, variable_test_data):
|
|||
assert condition.evaluate() is False
|
||||
|
||||
|
||||
def test_lazy_conditions_rich_comparison(pub, variable_test_data):
|
||||
condition = Condition({'type': 'django', 'value': 'form_var_foo_foo < "bar"'})
|
||||
assert condition.evaluate() is False
|
||||
|
||||
condition = Condition({'type': 'django', 'value': 'form_var_foo_foo <= "bar"'})
|
||||
assert condition.evaluate() is True
|
||||
|
||||
condition = Condition({'type': 'django', 'value': 'form_var_foo_foo >= "bar"'})
|
||||
assert condition.evaluate() is True
|
||||
|
||||
condition = Condition({'type': 'django', 'value': 'form_var_foo_foo > "bar"'})
|
||||
assert condition.evaluate() is False
|
||||
|
||||
|
||||
def test_has_role_templatefilter(pub, variable_test_data):
|
||||
condition = Condition({'type': 'django', 'value': 'form_user|has_role:"foobar"'})
|
||||
assert condition.evaluate() is False
|
||||
|
|
|
@ -1107,6 +1107,18 @@ class LazyFieldVar:
|
|||
def __ne__(self, other):
|
||||
return force_str(self) != force_str(other)
|
||||
|
||||
def __lt__(self, other):
|
||||
return force_str(self) < force_str(other)
|
||||
|
||||
def __le__(self, other):
|
||||
return force_str(self) <= force_str(other)
|
||||
|
||||
def __gt__(self, other):
|
||||
return force_str(self) > force_str(other)
|
||||
|
||||
def __ge__(self, other):
|
||||
return force_str(self) >= force_str(other)
|
||||
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, (int, slice)):
|
||||
return self.get_value()[key]
|
||||
|
|
Loading…
Reference in New Issue