data: allow missing link_page on LinkCell import (#60320)
This commit is contained in:
parent
287421122f
commit
4c6709c91e
|
@ -1463,6 +1463,19 @@ class LinkCell(CellBase):
|
|||
self.check_validity()
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
@utils.cache_during_request
|
||||
def get_page_slugs():
|
||||
return {page.slug for page in Page.objects.all()}
|
||||
|
||||
@classmethod
|
||||
def prepare_serialized_data(cls, cell_data):
|
||||
if 'link_page' in cell_data['fields']:
|
||||
link_page_slug = cell_data['fields']['link_page'][0].strip('/').split('/')[-1]
|
||||
if link_page_slug not in cls.get_page_slugs():
|
||||
del cell_data['fields']['link_page']
|
||||
return cell_data
|
||||
|
||||
def get_additional_label(self):
|
||||
title = self.title
|
||||
if not title and self.link_page:
|
||||
|
|
|
@ -21,7 +21,7 @@ from combo.apps.gallery.models import GalleryCell, Image
|
|||
from combo.apps.lingo.models import PaymentBackend, Regie
|
||||
from combo.apps.maps.models import Map, MapLayer, MapLayerOptions
|
||||
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings
|
||||
from combo.data.models import Page, SiteSettings, TextCell
|
||||
from combo.data.models import LinkCell, Page, SiteSettings, TextCell
|
||||
from combo.data.utils import MissingGroups, export_site, import_site
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
@ -519,3 +519,18 @@ def test_import_export_settings(app):
|
|||
site_settings.refresh_from_db()
|
||||
assert site_settings.initial_login_page_path == ''
|
||||
assert site_settings.welcome_page_path == ''
|
||||
|
||||
|
||||
def test_import_export_linkcell_to_missing_page(app, admin_user):
|
||||
page1 = Page.objects.create(title='One', slug='one')
|
||||
page2 = Page.objects.create(title='Two', slug='two')
|
||||
LinkCell.objects.create(page=page1, link_page=page2, placeholder='content', order=0)
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
payload = json.loads(output)
|
||||
del payload['pages'][1]
|
||||
import_site(data=payload, clean=True)
|
||||
|
||||
cell = LinkCell.objects.get()
|
||||
assert cell.link_page is None
|
||||
assert cell.get_validity_info().invalid_reason_code == 'data_url_not_defined'
|
||||
|
|
|
@ -926,7 +926,7 @@ def test_site_export_import_json(app, admin_user):
|
|||
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json')
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = resp.form.submit()
|
||||
assert len(ctx.captured_queries) in [308, 309]
|
||||
assert len(ctx.captured_queries) in [309, 310]
|
||||
assert Page.objects.count() == 4
|
||||
assert PageSnapshot.objects.all().count() == 4
|
||||
|
||||
|
@ -937,7 +937,7 @@ def test_site_export_import_json(app, admin_user):
|
|||
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json')
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = resp.form.submit()
|
||||
assert len(ctx.captured_queries) == 277
|
||||
assert len(ctx.captured_queries) == 278
|
||||
assert set(Page.objects.get(slug='one').related_cells['cell_types']) == {'data_textcell', 'data_linkcell'}
|
||||
assert Page.objects.count() == 4
|
||||
assert LinkCell.objects.count() == 2
|
||||
|
|
Loading…
Reference in New Issue