wcs: snapshot loading with old card cells (#68140)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-08-12 15:35:24 +02:00
parent 4019081d34
commit 574228c0b8
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 213 additions and 1 deletions

View File

@ -605,6 +605,16 @@ class Page(models.Model):
def load_serialized_cells(cls, cells): def load_serialized_cells(cls, cells):
# load new cells # load new cells
for cell_data in cells: for cell_data in cells:
# legacy card cells, for snapshots
if cell_data['model'] == 'wcs.wcscardinfoscell':
cell_data['model'] = 'wcs.wcscardcell'
elif cell_data['model'] == 'wcs.wcscardscell':
cell_data['model'] = 'wcs.wcscardcell'
cell_data['fields']['related_card_path'] = '__all__'
cell_data['fields']['display_mode'] = 'table'
cell_data['fields']['title_type'] = 'auto'
if cell_data['fields'].get('custom_title'):
cell_data['fields']['title_type'] = 'manual'
model = apps.get_model(cell_data['model']) model = apps.get_model(cell_data['model'])
cell_data = model.prepare_serialized_data(cell_data) cell_data = model.prepare_serialized_data(cell_data)
cell = list(serializers.deserialize('json', json.dumps([cell_data]), ignorenonexistent=True))[0] cell = list(serializers.deserialize('json', json.dumps([cell_data]), ignorenonexistent=True))[0]

View File

@ -14,7 +14,7 @@ from requests.models import Response
from combo.apps.wcs.forms import WcsCardCellDisplayForm from combo.apps.wcs.forms import WcsCardCellDisplayForm
from combo.apps.wcs.models import WcsCardCell from combo.apps.wcs.models import WcsCardCell
from combo.data.models import Page, TextCell, ValidityInfo from combo.data.models import Page, PageSnapshot, TextCell, ValidityInfo
from tests.test_manager import login from tests.test_manager import login
from tests.utils import manager_submit_cell from tests.utils import manager_submit_cell
@ -2511,3 +2511,205 @@ def test_card_cell_assets(mock_send, settings, app, admin_user):
resp = app.get('/manage/assets/') resp = app.get('/manage/assets/')
assert 'Picture — %s' % cell1.get_label_for_asset() in resp.text assert 'Picture — %s' % cell1.get_label_for_asset() in resp.text
assert 'Logo — %s' % cell2.get_label_for_asset() in resp.text assert 'Logo — %s' % cell2.get_label_for_asset() in resp.text
def test_page_snapshot_with_old_card_cells():
"""
page_serialization = {
'cells': [{
'model': 'data.parentcontentcell',
'fields': {
'slug': '',
'order': 0,
'groups': [],
'public': True,
'condition': None,
'placeholder': 'footer',
'template_name': None,
'extra_css_class': '',
'last_update_timestamp': '2022-08-08T13:55:29.599Z',
'restricted_to_unlogged': False,
'page': 14
}
}, {
'model': 'wcs.wcscardinfoscell',
'fields': {
'slug': 'enfant',
'limit': None,
'order': 1,
'groups': [],
'public': True,
'card_ids': '',
'condition': '',
'title_type': 'auto',
'placeholder': 'content',
'custom_title': '',
'display_mode': 'card',
'without_user': False,
'custom_schema': {},
'only_for_user': False,
'template_name': None,
'extra_css_class': '',
'carddef_reference': 'eservices:test-related-enfant',
'related_card_path': '',
'last_update_timestamp': '2022-08-11T13:57:43.362Z',
'restricted_to_unlogged': False,
'page': 14
}
}, {
'model': 'wcs.wcscardinfoscell',
'fields': {
'slug': '',
'limit': None,
'order': 2,
'groups': [],
'public': True,
'card_ids': '',
'condition': '',
'title_type': 'auto',
'placeholder': 'content',
'custom_title': '',
'display_mode': 'card',
'without_user': False,
'custom_schema': {},
'only_for_user': False,
'template_name': None,
'extra_css_class': '',
'carddef_reference': 'eservices:test-related-adulte:par-defaut',
'related_card_path': 'enfant/block_parents_parent',
'last_update_timestamp': '2022-08-08T19:53:02.097Z',
'restricted_to_unlogged': False,
'page': 14
}
}, {
'model': 'wcs.wcscardinfoscell',
'fields': {
'slug': '',
'limit': None,
'order': 3,
'groups': [],
'public': True,
'card_ids': '',
'condition': '',
'title_type': 'empty',
'placeholder': 'content',
'custom_title': 'Les parents !',
'display_mode': 'table',
'without_user': False,
'custom_schema': {},
'only_for_user': False,
'template_name': None,
'extra_css_class': '',
'carddef_reference': 'eservices:test-related-adulte:par-defaut',
'related_card_path': 'enfant/block_parents_parent',
'last_update_timestamp': '2022-08-11T13:07:35.757Z',
'restricted_to_unlogged': False,
'page': 14
}
}],
'fields': {
'slug': 'related-enfant',
'order': 6,
'title': 'Related enfant',
'groups': [],
'parent': ['search-related'],
'public': True,
'picture': '',
'snapshot': None,
'sub_slug': 'test-related-enfant_id',
'edit_role': None,
'description': '',
'redirect_url': '',
'template_name': 'standard',
'extra_variables': {},
'creation_timestamp': '2022-08-08T13:55:29.502Z',
'subpages_edit_role': None,
'placeholder_options': {},
'last_update_timestamp': '2022-08-11T13:57:43.369Z',
'exclude_from_navigation': True
},
'model': 'data.page',
'pk': 14
}
"""
page = Page.objects.create(title='xxx', slug='test_snapshots', template_name='standard')
PageSnapshot.take(page)
snapshot = page.pagesnapshot_set.first()
snapshot.serialization['cells'].append(
{
'model': 'wcs.wcscardinfoscell',
'fields': {
'slug': 'my-card',
'limit': 42,
'order': 1,
'groups': [],
'public': True,
'card_ids': '42,35',
'condition': 'my-condition',
'title_type': 'manual',
'placeholder': 'content',
'custom_title': 'my-title',
'display_mode': 'card',
'without_user': True,
'custom_schema': {},
'only_for_user': True,
'template_name': None,
'extra_css_class': '',
'carddef_reference': 'default:card_model_1',
'related_card_path': '',
'last_update_timestamp': '2022-08-11T13:57:43.362Z',
'restricted_to_unlogged': False,
'page': page.pk,
},
}
)
snapshot.serialization['cells'].append(
{
'model': 'wcs.wcscardscell',
'fields': {
'slug': 'my-other-card',
'limit': 35,
'order': 2,
'groups': [],
'public': True,
'condition': '',
'placeholder': 'content',
'custom_title': 'my-other-title',
'without_user': False,
'only_for_user': False,
'template_name': None,
'extra_css_class': '',
'carddef_reference': 'default:card_model_1',
'last_update_timestamp': '2022-08-12T07:19:18.541Z',
'restricted_to_unlogged': False,
'page': page.pk,
},
}
)
old_page = snapshot.get_page()
cell1 = old_page.get_cells()[0]
assert isinstance(cell1, WcsCardCell)
assert cell1.slug == 'my-card'
assert cell1.limit == 42
assert cell1.card_ids == '42,35'
assert cell1.title_type == 'manual'
assert cell1.custom_title == 'my-title'
assert cell1.display_mode == 'card'
assert cell1.without_user is True
assert cell1.custom_schema == {}
assert cell1.only_for_user is True
assert cell1.carddef_reference == 'default:card_model_1'
assert cell1.related_card_path == ''
cell2 = old_page.get_cells()[1]
assert isinstance(cell1, WcsCardCell)
assert cell2.slug == 'my-other-card'
assert cell2.limit == 35
assert cell2.card_ids == ''
assert cell2.title_type == 'manual'
assert cell2.custom_title == 'my-other-title'
assert cell2.display_mode == 'table'
assert cell2.without_user is False
assert cell2.custom_schema == {}
assert cell2.only_for_user is False
assert cell2.carddef_reference == 'default:card_model_1'
assert cell2.related_card_path == '__all__'