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 09:43

Télécharger (3,9 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                        | 43 +++++++++++++++++++
 4 files changed, 57 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
2387 2387
    cell.render(context)
2388 2388
    assert 'NameID' not in mock_send.call_args_list[0][0][0].url
2389 2389
    assert 'email' not in mock_send.call_args_list[0][0][0].url
2390

  
2391

  
2392
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
2393
def test_card_cell_assets(mock_send, settings, app, admin_user):
2394
    page = Page.objects.create(title='xxx', slug='test_cell_assets', template_name='standard')
2395
    cell1 = WcsCardInfosCell.objects.create(
2396
        page=page,
2397
        placeholder='content',
2398
        order=0,
2399
        carddef_reference='default:card_model_1',
2400
        display_mode='card',
2401
        slug='slug1',
2402
    )
2403
    cell2 = WcsCardInfosCell.objects.create(
2404
        page=page,
2405
        placeholder='content',
2406
        order=0,
2407
        carddef_reference='default:card_model_1',
2408
        display_mode='table',
2409
        slug='slug2',
2410
    )
2411

  
2412
    app = login(app)
2413
    settings.COMBO_CELL_ASSET_SLOTS = {}
2414
    resp = app.get('/manage/assets/')
2415
    assert 'have any asset yet.' in resp.text
2416

  
2417
    settings.COMBO_CELL_ASSET_SLOTS = {
2418
        'wcs_wcscardscell': {
2419
            'logo': {
2420
                'prefix': 'Logo',
2421
            },
2422
        },
2423
        'wcs_wcscardinfoscell': {
2424
            'picture': {
2425
                'prefix': 'Picture',
2426
            },
2427
        },
2428
    }
2429
    resp = app.get('/manage/assets/')
2430
    print(resp)
2431
    assert 'Picture — %s' % cell1.get_label_for_asset() in resp.text
2432
    assert 'Logo — %s' % cell2.get_label_for_asset() in resp.text
2390
-