From 0712cbe5d60091100d565bba023c76337a7cce26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Fri, 12 Aug 2022 09:41:28 +0200 Subject: [PATCH] wcs: card cell with table mode can use cards cell assets (#68063) --- combo/apps/wcs/models.py | 12 ++++++ combo/apps/wcs/templates/combo/wcs/card.html | 2 +- combo/apps/wcs/templates/combo/wcs/cards.html | 2 +- tests/wcs/test_card.py | 42 +++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py index 75540a9c..8c0368c8 100644 --- a/combo/apps/wcs/models.py +++ b/combo/apps/wcs/models.py @@ -1605,6 +1605,18 @@ class WcsCardInfosCell(CardMixin, CellBase): return custom_schema + def get_asset_slot_key(self, key): + if self.display_mode == 'table': + # for legacy: card cell with table mode should use assets of old cards cell + return 'cell:wcs_wcscardscell:%s:%s' % (key, self.get_slug_for_asset()) + return super().get_asset_slot_key(key) + + def get_asset_slot_templates(self): + if self.display_mode == 'table' and settings.COMBO_CELL_ASSET_SLOTS.get('wcs_wcscardscell'): + # for legacy: card cell with table mode should use assets of old cards cell + return settings.COMBO_CELL_ASSET_SLOTS['wcs_wcscardscell'] + return super().get_asset_slot_templates() + @register_cell_class class TrackingCodeInputCell(CellBase): diff --git a/combo/apps/wcs/templates/combo/wcs/card.html b/combo/apps/wcs/templates/combo/wcs/card.html index 513d14f8..205e360d 100644 --- a/combo/apps/wcs/templates/combo/wcs/card.html +++ b/combo/apps/wcs/templates/combo/wcs/card.html @@ -1,4 +1,4 @@ -{% load assets i18n %} +{% load i18n %} {% block cell-content %} {% if not card_not_found %} diff --git a/combo/apps/wcs/templates/combo/wcs/cards.html b/combo/apps/wcs/templates/combo/wcs/cards.html index a7edd9f0..bb1b368c 100644 --- a/combo/apps/wcs/templates/combo/wcs/cards.html +++ b/combo/apps/wcs/templates/combo/wcs/cards.html @@ -1,4 +1,4 @@ -{% load assets i18n %} +{% load i18n %} {% block cell-content %} diff --git a/tests/wcs/test_card.py b/tests/wcs/test_card.py index 02496ea9..8b9f4854 100644 --- a/tests/wcs/test_card.py +++ b/tests/wcs/test_card.py @@ -2471,3 +2471,45 @@ def test_card_file_redirection(mock_send, app): # invalid session key resp = app.get(file_url.replace('file/', 'file/X'), status=403) + + +@mock.patch('requests.Session.send', side_effect=mocked_requests_send) +def test_card_cell_assets(mock_send, settings, app, admin_user): + page = Page.objects.create(title='xxx', slug='test_cell_assets', template_name='standard') + cell1 = WcsCardInfosCell.objects.create( + page=page, + placeholder='content', + order=0, + carddef_reference='default:card_model_1', + display_mode='card', + slug='slug1', + ) + cell2 = WcsCardInfosCell.objects.create( + page=page, + placeholder='content', + order=0, + carddef_reference='default:card_model_1', + display_mode='table', + slug='slug2', + ) + + app = login(app) + settings.COMBO_CELL_ASSET_SLOTS = {} + resp = app.get('/manage/assets/') + assert 'have any asset yet.' in resp.text + + settings.COMBO_CELL_ASSET_SLOTS = { + 'wcs_wcscardscell': { + 'logo': { + 'prefix': 'Logo', + }, + }, + 'wcs_wcscardinfoscell': { + 'picture': { + 'prefix': 'Picture', + }, + }, + } + resp = app.get('/manage/assets/') + assert 'Picture — %s' % cell1.get_label_for_asset() in resp.text + assert 'Logo — %s' % cell2.get_label_for_asset() in resp.text