wcs: add card schema in manager form (#52498)
This commit is contained in:
parent
e939770c0c
commit
03f1ac9cd0
|
@ -857,6 +857,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
|
|||
is_enabled = classmethod(is_wcs_enabled)
|
||||
|
||||
template_name = 'combo/wcs/card.html'
|
||||
manager_form_template = 'combo/wcs/manager/card-infos-cell-form.html'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Card Information Cell')
|
||||
|
@ -909,6 +910,13 @@ class WcsCardInfosCell(CardMixin, CellBase):
|
|||
card_id = '%s_id' % card_slug
|
||||
return context.get(card_id) or None
|
||||
|
||||
def get_extra_manager_context(self):
|
||||
extra_context = super().get_extra_manager_context()
|
||||
if self.cached_json:
|
||||
extra_context['card_schema'] = self.cached_json
|
||||
extra_context['card_schema_id'] = 'cell-%s-card-schema-%s' % (self.pk, self.carddef_reference)
|
||||
return extra_context
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
extra_context = super().get_cell_extra_context(context)
|
||||
extra_context['title'] = self.cached_title
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{% extends "combo/cell_form.html" %}
|
||||
|
||||
{% block cell-form %}
|
||||
{{ block.super }}
|
||||
{% if card_schema %}
|
||||
{{ card_schema|json_script:card_schema_id }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -557,6 +557,7 @@ class PageEditCellView(UpdateView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PageEditCellView, self).get_context_data(**kwargs)
|
||||
context.update(self.get_object().get_extra_manager_context())
|
||||
context['cell'] = self.get_object()
|
||||
context['page'] = context['cell'].page
|
||||
return context
|
||||
|
|
|
@ -1395,6 +1395,21 @@ def test_card_cell_validity(mock_send):
|
|||
assert validity_info.invalid_since is not None
|
||||
|
||||
|
||||
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
|
||||
def test_manager_card_cell(mock_send, app, admin_user):
|
||||
page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard')
|
||||
cell = WcsCardInfosCell(page=page, placeholder='content', order=0)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||
assert 'application/json' not in resp
|
||||
|
||||
cell.carddef_reference = 'default:card_model_1'
|
||||
cell.save()
|
||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||
assert '<script id="cell-%s-card-schema-default:card_model_1" type="application/json">' % cell.pk in resp
|
||||
|
||||
|
||||
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
|
||||
def test_card_cell_load(mock_send):
|
||||
page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard')
|
||||
|
|
Loading…
Reference in New Issue