data: fix import of nested subpages (#56794)
This commit is contained in:
parent
b62f5537bd
commit
6bb24b1611
|
@ -550,7 +550,7 @@ class Page(models.Model):
|
|||
page, created = Page.objects.get_or_create(slug=json_page['fields']['slug'], snapshot=snapshot)
|
||||
json_page['pk'] = page.id
|
||||
parent_slug = json_page['fields'].get('parent') or []
|
||||
if parent_slug and not Page.objects.filter(slug=parent_slug[0]).exists():
|
||||
if parent_slug and not Page.objects.filter(slug=parent_slug[0].split('/')[-1]).exists():
|
||||
# parent not found, remove it and exclude page from navigation
|
||||
json_page['fields'].pop('parent')
|
||||
json_page['fields']['exclude_from_navigation'] = True
|
||||
|
|
|
@ -123,6 +123,22 @@ def test_import_export_with_unknown_parent(app, some_data):
|
|||
assert one.exclude_from_navigation is True
|
||||
|
||||
|
||||
def test_import_export_with_nested_parents():
|
||||
one = Page.objects.create(title='One', slug='one')
|
||||
two = Page.objects.create(title='Two', slug='two', parent=one)
|
||||
Page.objects.create(title='Three', slug='three', parent=two)
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
Page.objects.all().delete()
|
||||
import_site(data=json.loads(output))
|
||||
|
||||
assert Page.objects.count() == 3
|
||||
two = Page.objects.get(slug='two')
|
||||
assert two.parent.slug == 'one'
|
||||
two = Page.objects.get(slug='three')
|
||||
assert two.parent.slug == 'two'
|
||||
|
||||
|
||||
def test_backward_compatibility_import(app, some_data):
|
||||
old_export = Page.export_all_for_json()
|
||||
Page.objects.all().delete()
|
||||
|
|
|
@ -878,7 +878,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 [303, 304]
|
||||
assert len(ctx.captured_queries) in [307, 308]
|
||||
assert Page.objects.count() == 4
|
||||
assert PageSnapshot.objects.all().count() == 4
|
||||
|
||||
|
@ -889,7 +889,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) == 272
|
||||
assert len(ctx.captured_queries) == 276
|
||||
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