wcs: fix mix of category filter and no status filter (#21484)
This commit is contained in:
parent
09396d6e4d
commit
d7bb7c6549
|
@ -302,22 +302,25 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
|
|||
for category in self.categories.get('data', []):
|
||||
categories_filter[tuple(category.split(':'))] = True
|
||||
|
||||
if not (self.current_forms and self.done_forms):
|
||||
for wcs_site in context['user_forms']:
|
||||
if not context['user_forms'].get(wcs_site):
|
||||
continue
|
||||
if not context['user_forms'][wcs_site].get('data'):
|
||||
continue
|
||||
forms = context['user_forms'][wcs_site]['data']
|
||||
if categories_filter:
|
||||
forms = [x for x in forms if (wcs_site, x.get('category_slug')) in categories_filter]
|
||||
if self.current_forms:
|
||||
forms = [x for x in forms if not x.get('form_status_is_endpoint')]
|
||||
elif self.done_forms:
|
||||
forms = [x for x in forms if x.get('form_status_is_endpoint')]
|
||||
context['user_forms'][wcs_site]['data'] = forms # put it back
|
||||
for wcs_site in context['user_forms']:
|
||||
if not context['user_forms'].get(wcs_site):
|
||||
continue
|
||||
if not context['user_forms'][wcs_site].get('data'):
|
||||
continue
|
||||
forms = context['user_forms'][wcs_site]['data']
|
||||
if categories_filter:
|
||||
forms = [x for x in forms if (wcs_site, x.get('category_slug')) in categories_filter]
|
||||
if self.current_forms and self.done_forms:
|
||||
pass # keep them all
|
||||
elif self.current_forms:
|
||||
forms = [x for x in forms if not x.get('form_status_is_endpoint')]
|
||||
elif self.done_forms:
|
||||
forms = [x for x in forms if x.get('form_status_is_endpoint')]
|
||||
else:
|
||||
forms = [] # nothing left
|
||||
context['user_forms'][wcs_site]['data'] = forms # put it back
|
||||
|
||||
context['current_forms'] = context['user_forms'] # legacy
|
||||
context['current_forms'] = context['user_forms'] # legacy
|
||||
|
||||
# regroup all forms in a flat list
|
||||
context['forms'] = []
|
||||
|
|
|
@ -348,6 +348,18 @@ def test_current_forms_cell_render(context):
|
|||
extra_context = cell.get_cell_extra_context(context)
|
||||
assert len(extra_context['forms']) == 5
|
||||
|
||||
# check both category limit and all forms
|
||||
cell.current_forms = True
|
||||
cell.done_forms = True
|
||||
extra_context = cell.get_cell_extra_context(context)
|
||||
assert len(extra_context['forms']) == 8
|
||||
|
||||
# check both category limit and no forms
|
||||
cell.current_forms = False
|
||||
cell.done_forms = False
|
||||
extra_context = cell.get_cell_extra_context(context)
|
||||
assert len(extra_context['forms']) == 0
|
||||
|
||||
@wcsctl_present
|
||||
def test_current_forms_cell_render_single_site(context):
|
||||
page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard')
|
||||
|
|
Loading…
Reference in New Issue