data: fix parent selection on import (#69194)
This commit is contained in:
parent
7e8b9318b2
commit
5972b44739
|
@ -573,7 +573,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].split('/')[-1]).exists():
|
||||
if parent_slug and not Page.objects.filter(slug=parent_slug[0].split('/')[-1] or 'index').exists():
|
||||
# parent not found, remove it and exclude page from navigation
|
||||
json_page['fields'].pop('parent')
|
||||
json_page['fields']['exclude_from_navigation'] = True
|
||||
|
@ -636,7 +636,7 @@ class Page(models.Model):
|
|||
# pre-create pages
|
||||
parent = None
|
||||
if json_page['fields'].get('parent'):
|
||||
parent = json_page['fields']['parent'][0].split('/')[-1]
|
||||
parent = json_page['fields']['parent'][0].split('/')[-1] or 'index'
|
||||
|
||||
page, created = Page.objects.get_or_create(
|
||||
slug=json_page['fields']['slug'], parent__slug=parent
|
||||
|
|
|
@ -529,6 +529,23 @@ def test_import_export_linkcell_to_missing_page(app, admin_user):
|
|||
assert cell.get_validity_info().invalid_reason_code == 'data_url_not_defined'
|
||||
|
||||
|
||||
def test_import_export_linkcell_to_cell_page(app, admin_user):
|
||||
root_page = Page.objects.create(title='Home', slug='index')
|
||||
page = Page.objects.create(title='One', slug='one', parent=root_page)
|
||||
LinkCell.objects.create(page=page, link_page=page, placeholder='content', order=0)
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
payload = json.loads(output)
|
||||
import_site(data=payload)
|
||||
|
||||
cell = LinkCell.objects.get()
|
||||
assert Page.objects.count() == 2
|
||||
root_page = Page.objects.get(slug='index')
|
||||
page = Page.objects.get(slug='one')
|
||||
assert cell.link_page == page
|
||||
assert page.parent == root_page
|
||||
|
||||
|
||||
def test_import_export_linkcell_to_url(app, admin_user):
|
||||
page1 = Page.objects.create(title='One', slug='one')
|
||||
LinkCell.objects.create(page=page1, url='https://example.com', placeholder='content', order=0)
|
||||
|
|
Loading…
Reference in New Issue