misc: ignore no_data fields in filter_by (#88454)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-03-21 12:29:45 +01:00
parent 89b4d350ab
commit 9c12c01712
3 changed files with 29 additions and 2 deletions

View File

@ -1997,6 +1997,31 @@ def test_lazy_formdata_queryset_filter_non_unique_varname(pub, variable_test_dat
assert tmpl.render(context) == '1'
def test_filter_on_page_field(pub):
pub.loggederror_class.wipe()
FormDef.wipe()
formdef = FormDef()
formdef.name = 'test'
formdef.fields = [
fields.PageField(id='1', label='Page', varname='page'),
]
formdef.store()
data_class = formdef.data_class()
formdata = data_class()
formdata.just_created()
formdata.store()
context = pub.substitutions.get_context_variables(mode='lazy')
tmpl = Template('{{forms|objects:"test"|filter_by:"page"|filter_value:"100"}}')
tmpl.render(context)
assert pub.loggederror_class.count() == 1
logged_error = pub.loggederror_class.select()[0]
assert logged_error.summary == 'Invalid filter "page"'
def test_numeric_filter_on_string(pub):
FormDef.wipe()
formdef = FormDef()

View File

@ -576,9 +576,11 @@ class FormDef(StorableObject):
def get_all_fields(self):
return (self.fields or []) + self.workflow.get_backoffice_fields()
def iter_fields(self, include_block_fields=False, with_backoffice_fields=True):
def iter_fields(self, include_block_fields=False, with_backoffice_fields=True, with_no_data_fields=True):
def _iter_fields(fields, block_field=None):
for field in fields:
if with_no_data_fields is False and field.is_no_data_field:
continue
# add contextual_id/contextual_varname attributes
# they are id/varname for normal fields
# but in case of blocks they are concatenation of block id/varname + field id/varname

View File

@ -270,7 +270,7 @@ class LazyFormDefObjectsManager:
return self._clone(self._criterias + [self._formdef.get_by_id_criteria(str(value))])
def get_fields(self, key):
for field in self._formdef.iter_fields(include_block_fields=True):
for field in self._formdef.iter_fields(include_block_fields=True, with_no_data_fields=False):
if getattr(field, 'block_field', None):
if field.key == 'items':
# not yet