Projet

Général

Profil

0001-wcs-add-card-schema-in-manager-form-52498.patch

Lauréline Guérin, 08 avril 2021 10:58

Télécharger (3,19 ko)

Voir les différences:

Subject: [PATCH] wcs: add card schema in manager form (#52498)

 combo/apps/wcs/models.py                          |  8 ++++++++
 .../combo/wcs/manager/card-infos-cell-form.html   |  8 ++++++++
 tests/test_wcs.py                                 | 15 +++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html
combo/apps/wcs/models.py
859 859
    is_enabled = classmethod(is_wcs_enabled)
860 860

  
861 861
    template_name = 'combo/wcs/card.html'
862
    manager_form_template = 'combo/wcs/manager/card-infos-cell-form.html'
862 863

  
863 864
    class Meta:
864 865
        verbose_name = _('Card Information Cell')
......
911 912
        card_id = '%s_id' % card_slug
912 913
        return context.get(card_id) or None
913 914

  
915
    def get_extra_manager_context(self):
916
        extra_context = super().get_extra_manager_context()
917
        if self.cached_json:
918
            extra_context['card_schema'] = self.cached_json
919
            extra_context['card_schema_id'] = 'card_schema-%s' % self.carddef_reference
920
        return extra_context
921

  
914 922
    def get_cell_extra_context(self, context):
915 923
        extra_context = super().get_cell_extra_context(context)
916 924
        extra_context['title'] = self.cached_title
combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html
1
{% extends "combo/cell_form.html" %}
2

  
3
{% block cell-form %}
4
{{ block.super }}
5
{% if card_schema %}
6
{{ card_schema|json_script:card_schema_id }}
7
{% endif %}
8
{% endblock %}
tests/test_wcs.py
1399 1399
    assert validity_info.invalid_since is not None
1400 1400

  
1401 1401

  
1402
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
1403
def test_manager_card_cell(mock_send, app, admin_user):
1404
    page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard')
1405
    cell = WcsCardInfosCell(page=page, placeholder='content', order=0)
1406

  
1407
    app = login(app)
1408
    resp = app.get('/manage/pages/%s/' % page.pk)
1409
    assert 'application/json' not in resp
1410

  
1411
    cell.carddef_reference = 'default:card_model_1'
1412
    cell.save()
1413
    resp = app.get('/manage/pages/%s/' % page.pk)
1414
    assert '<script id="card_schema-default:card_model_1" type="application/json">' in resp
1415

  
1416

  
1402 1417
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
1403 1418
def test_card_cell_load(mock_send):
1404 1419
    page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard')
1405
-