wcs: add repeat_index in context (#59803)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2021-12-16 17:36:54 +01:00 committed by Frédéric Péters
parent b6cb9194b7
commit 2ee49ebd45
2 changed files with 31 additions and 1 deletions

View File

@ -1041,6 +1041,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
extra_context['card'] = response.json()
custom_context = Context(extra_context)
custom_context.update(context)
custom_context['repeat_index'] = context.get('repeat_index') or 0
if self.title_type == 'manual':
try:
extra_context['title'] = Template(self.custom_title).render(custom_context)

View File

@ -1907,6 +1907,18 @@ def test_card_cell_render(mock_send, context, app):
cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[0])
assert '<h2>Xhttp://testserverY</h2>' in cell_resp
cell.card_ids = '{{ cards|objects:"card_model_1"|getlist:"id"|join:"," }}'
cell.title_type = 'manual'
cell.custom_title = 'Foo bar X{{ repeat_index }}Y'
cell.save()
resp = app.get(page.get_online_url())
assert len(resp.context['cells']) == 3
extra_ctx = re.findall(r'data-extra-context="(.*)"', resp.text)
for i in range(0, 3):
cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[i])
assert '<h2>Foo bar X%sY</h2>' % i in cell_resp
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
def test_card_cell_render_text_field(mock_send, context):
@ -1945,7 +1957,6 @@ def test_card_cell_render_email_field(mock_send, context):
page = Page.objects.create(title='xxx', template_name='standard')
cell = WcsCardInfosCell(page=page, placeholder='content', order=0)
cell.carddef_reference = 'default:card_model_1'
cell.custom_title = 'Foo bar {{ card.fields.title }}'
cell.save()
context['card_model_1_id'] = 11
@ -2064,6 +2075,24 @@ def test_card_cell_render_custom_schema(mock_send, context, app):
cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[0])
assert '<p class="label">Foo bar baz Xhttp://testserverY</p>' in cell_resp
cell.card_ids = '{{ cards|objects:"card_model_1"|getlist:"id"|join:"," }}'
cell.custom_schema = {
'cells': [
{'varname': '@custom@', 'template': 'Foo bar baz X{{ repeat_index }}Y', 'display_mode': 'label'},
]
}
cell.save()
resp = app.get(page.get_online_url())
assert len(resp.context['cells']) == 3
extra_ctx = re.findall(r'data-extra-context="(.*)"', resp.text)
cell_url = reverse(
'combo-public-ajax-page-cell',
kwargs={'page_pk': page.pk, 'cell_reference': cell.get_reference()},
)
for i in range(0, 3):
cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[i])
assert '<p class="label">Foo bar baz X%sY</p>' % i in cell_resp
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
def test_card_cell_render_identifier(mock_send, nocache, app):