wcs: provide flat lists of formdatas/drafts to templates (#20374)
This commit is contained in:
parent
921ab9f484
commit
31698ae4a9
|
@ -306,6 +306,16 @@ class WcsCurrentFormsCell(WcsUserDataBaseCell):
|
|||
context['user_forms'][wcs_site]['data'] = [x for x in
|
||||
context['user_forms'][wcs_site]['data'] if x.get('form_status_is_endpoint')]
|
||||
context['current_forms'] = context['user_forms'] # legacy
|
||||
|
||||
# regroup all forms in a flat list
|
||||
context['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
|
||||
context['forms'].extend(context['user_forms'][wcs_site]['data'])
|
||||
|
||||
return context
|
||||
|
||||
@register_cell_class
|
||||
|
@ -317,6 +327,19 @@ class WcsCurrentDraftsCell(WcsUserDataBaseCell):
|
|||
class Meta:
|
||||
verbose_name = _('Current Drafts')
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
context = super(WcsCurrentDraftsCell, self).get_cell_extra_context(context)
|
||||
|
||||
# regroup all drafts in a flat list
|
||||
context['drafts'] = []
|
||||
for wcs_site in context['current_drafts']:
|
||||
if not context['current_drafts'].get(wcs_site):
|
||||
continue
|
||||
if not context['current_drafts'][wcs_site].get('data'):
|
||||
continue
|
||||
context['drafts'].extend(context['current_drafts'][wcs_site]['data'])
|
||||
|
||||
return context
|
||||
|
||||
@register_cell_class
|
||||
class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin):
|
||||
|
|
|
@ -346,6 +346,12 @@ def test_current_forms_cell_render(context):
|
|||
assert data['default']['data'][0]['site_slug'] == 'default'
|
||||
assert data['other']['data'][0]['site_slug'] == 'other'
|
||||
|
||||
# check flat list
|
||||
extra_context = cell.get_cell_extra_context(context)
|
||||
assert len(extra_context['forms']) == 10
|
||||
assert len([x for x in extra_context['forms'] if x['site_slug'] == 'default']) == 5
|
||||
assert len([x for x in extra_context['forms'] if x['site_slug'] == 'other']) == 5
|
||||
|
||||
@wcsctl_present
|
||||
def test_current_forms_cell_render_single_site(context):
|
||||
page = Page(title='xxx', slug='test_current_forms_cell_render', template_name='standard')
|
||||
|
@ -459,3 +465,9 @@ def test_current_drafts_cell_render_logged_in(context):
|
|||
assert 'http://127.0.0.1:8999/third-form-title/1' in result
|
||||
for url in re.findall('href="(.*)"', result):
|
||||
check_wcs_open(url)
|
||||
|
||||
# check flat list
|
||||
extra_context = cell.get_cell_extra_context(context)
|
||||
assert len(extra_context['drafts']) == 2
|
||||
assert len([x for x in extra_context['drafts'] if x['site_slug'] == 'default']) == 1
|
||||
assert len([x for x in extra_context['drafts'] if x['site_slug'] == 'other']) == 1
|
||||
|
|
Loading…
Reference in New Issue