Projet

Général

Profil

0008-wcs-card-cell-with-table-mode-can-use-cards-cell-ass.patch

Lauréline Guérin, 12 août 2022 13:34

Télécharger (3,8 ko)

Voir les différences:

Subject: [PATCH 8/8] 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(-)
combo/apps/wcs/models.py
1600 1600

  
1601 1601
        return custom_schema
1602 1602

  
1603
    def get_asset_slot_key(self, key):
1604
        if self.display_mode == 'table':
1605
            # for legacy: card cell with table mode should use assets of old cards cell
1606
            return 'cell:wcs_wcscardscell:%s:%s' % (key, self.get_slug_for_asset())
1607
        return super().get_asset_slot_key(key)
1608

  
1609
    def get_asset_slot_templates(self):
1610
        if self.display_mode == 'table' and settings.COMBO_CELL_ASSET_SLOTS.get('wcs_wcscardscell'):
1611
            # for legacy: card cell with table mode should use assets of old cards cell
1612
            return settings.COMBO_CELL_ASSET_SLOTS['wcs_wcscardscell']
1613
        return super().get_asset_slot_templates()
1614

  
1603 1615

  
1604 1616
@register_cell_class
1605 1617
class TrackingCodeInputCell(CellBase):
combo/apps/wcs/templates/combo/wcs/card.html
1
{% load assets i18n %}
1
{% load i18n %}
2 2

  
3 3
{% block cell-content %}
4 4
{% if not card_not_found %}
combo/apps/wcs/templates/combo/wcs/cards.html
1
{% load assets i18n %}
1
{% load i18n %}
2 2

  
3 3
{% block cell-content %}
4 4

  
tests/wcs/test_card.py
2471 2471

  
2472 2472
    # invalid session key
2473 2473
    resp = app.get(file_url.replace('file/', 'file/X'), status=403)
2474

  
2475

  
2476
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
2477
def test_card_cell_assets(mock_send, settings, app, admin_user):
2478
    page = Page.objects.create(title='xxx', slug='test_cell_assets', template_name='standard')
2479
    cell1 = WcsCardInfosCell.objects.create(
2480
        page=page,
2481
        placeholder='content',
2482
        order=0,
2483
        carddef_reference='default:card_model_1',
2484
        display_mode='card',
2485
        slug='slug1',
2486
    )
2487
    cell2 = WcsCardInfosCell.objects.create(
2488
        page=page,
2489
        placeholder='content',
2490
        order=0,
2491
        carddef_reference='default:card_model_1',
2492
        display_mode='table',
2493
        slug='slug2',
2494
    )
2495

  
2496
    app = login(app)
2497
    settings.COMBO_CELL_ASSET_SLOTS = {}
2498
    resp = app.get('/manage/assets/')
2499
    assert 'have any asset yet.' in resp.text
2500

  
2501
    settings.COMBO_CELL_ASSET_SLOTS = {
2502
        'wcs_wcscardscell': {
2503
            'logo': {
2504
                'prefix': 'Logo',
2505
            },
2506
        },
2507
        'wcs_wcscardinfoscell': {
2508
            'picture': {
2509
                'prefix': 'Picture',
2510
            },
2511
        },
2512
    }
2513
    resp = app.get('/manage/assets/')
2514
    assert 'Picture — %s' % cell1.get_label_for_asset() in resp.text
2515
    assert 'Logo — %s' % cell2.get_label_for_asset() in resp.text
2474
-