0001-wcs-add-card-schema-in-manager-form-52498.patch
combo/apps/wcs/models.py | ||
---|---|---|
857 | 857 |
is_enabled = classmethod(is_wcs_enabled) |
858 | 858 | |
859 | 859 |
template_name = 'combo/wcs/card.html' |
860 |
manager_form_template = 'combo/wcs/manager/card-infos-cell-form.html' |
|
860 | 861 | |
861 | 862 |
class Meta: |
862 | 863 |
verbose_name = _('Card Information Cell') |
... | ... | |
909 | 910 |
card_id = '%s_id' % card_slug |
910 | 911 |
return context.get(card_id) or None |
911 | 912 | |
913 |
def get_extra_manager_context(self): |
|
914 |
extra_context = super().get_extra_manager_context() |
|
915 |
if self.cached_json: |
|
916 |
extra_context['card_schema'] = self.cached_json |
|
917 |
extra_context['card_schema_id'] = 'cell-%s-card-schema-%s' % (self.pk, self.carddef_reference) |
|
918 |
return extra_context |
|
919 | ||
912 | 920 |
def get_cell_extra_context(self, context): |
913 | 921 |
extra_context = super().get_cell_extra_context(context) |
914 | 922 |
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 %} |
combo/manager/views.py | ||
---|---|---|
557 | 557 | |
558 | 558 |
def get_context_data(self, **kwargs): |
559 | 559 |
context = super(PageEditCellView, self).get_context_data(**kwargs) |
560 |
context.update(self.get_object().get_extra_manager_context()) |
|
560 | 561 |
context['cell'] = self.get_object() |
561 | 562 |
context['page'] = context['cell'].page |
562 | 563 |
return context |
tests/test_wcs.py | ||
---|---|---|
1395 | 1395 |
assert validity_info.invalid_since is not None |
1396 | 1396 | |
1397 | 1397 | |
1398 |
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) |
|
1399 |
def test_manager_card_cell(mock_send, app, admin_user): |
|
1400 |
page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard') |
|
1401 |
cell = WcsCardInfosCell(page=page, placeholder='content', order=0) |
|
1402 | ||
1403 |
app = login(app) |
|
1404 |
resp = app.get('/manage/pages/%s/' % page.pk) |
|
1405 |
assert 'application/json' not in resp |
|
1406 | ||
1407 |
cell.carddef_reference = 'default:card_model_1' |
|
1408 |
cell.save() |
|
1409 |
resp = app.get('/manage/pages/%s/' % page.pk) |
|
1410 |
assert '<script id="cell-%s-card-schema-default:card_model_1" type="application/json">' % cell.pk in resp |
|
1411 | ||
1412 | ||
1398 | 1413 |
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) |
1399 | 1414 |
def test_card_cell_load(mock_send): |
1400 | 1415 |
page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard') |
1401 |
- |