import: remove pk, page, placeholder in link list items (#43620)
This commit is contained in:
parent
f5a5299a54
commit
c6b0ebb5a1
|
@ -1304,17 +1304,22 @@ class LinkListCell(CellBase):
|
|||
return LinkListCellForm
|
||||
|
||||
def export_subobjects(self):
|
||||
return {'links': json.loads(
|
||||
links = json.loads(
|
||||
serializers.serialize(
|
||||
'json',
|
||||
self.get_items(),
|
||||
use_natural_foreign_keys=True,
|
||||
use_natural_primary_keys=True)
|
||||
)}
|
||||
use_natural_primary_keys=True))
|
||||
for link in links:
|
||||
del link['pk']
|
||||
del link['fields']['placeholder']
|
||||
del link['fields']['page']
|
||||
return {'links': links}
|
||||
|
||||
def import_subobjects(self, cell_json):
|
||||
for link in cell_json['links']:
|
||||
link['fields']['placeholder'] = self.link_placeholder
|
||||
link['fields']['page'] = self.page_id
|
||||
links = serializers.deserialize('json', json.dumps(cell_json['links']), ignorenonexistent=True)
|
||||
for link in links:
|
||||
link.save()
|
||||
|
|
|
@ -167,6 +167,7 @@ def test_import_export_pages():
|
|||
assert isinstance(CellBase.get_cells(page_id=new_page_1.id)[0], TextCell)
|
||||
assert CellBase.get_cells(page_id=new_page_1.id)[0].text == 'foo'
|
||||
|
||||
|
||||
def test_import_export_pages_with_links():
|
||||
page = Page(title=u'foo', slug='foo', order=0)
|
||||
page.save()
|
||||
|
@ -199,6 +200,14 @@ def test_import_export_pages_with_links():
|
|||
site_export = [x.get_serialized_page() for x in Page.objects.all()]
|
||||
Page.objects.all().delete()
|
||||
|
||||
for page in site_export:
|
||||
for cell in page['cells']:
|
||||
if 'links' not in cell:
|
||||
continue
|
||||
for link in cell['links']:
|
||||
assert 'pk' not in link
|
||||
assert 'placeholder' not in link['fields']
|
||||
assert 'page' not in link['fields']
|
||||
Page.load_serialized_pages(site_export)
|
||||
|
||||
new_page_1 = Page.objects.all().order_by('order')[0]
|
||||
|
@ -213,11 +222,13 @@ def test_import_export_pages_with_links():
|
|||
assert new_item_1.title == item1.title
|
||||
assert new_item_1.url == item1.url
|
||||
assert new_item_1.link_page is None
|
||||
assert new_item_1.pk != item1.pk
|
||||
new_item_2 = new_cells_1[1].get_items()[1]
|
||||
assert isinstance(new_item_2, LinkCell)
|
||||
assert new_item_2.title == item2.title
|
||||
assert new_item_2.url == ''
|
||||
assert new_item_2.link_page == new_page_2
|
||||
assert new_item_2.pk != item2.pk
|
||||
|
||||
|
||||
def test_duplicate_page():
|
||||
|
|
Loading…
Reference in New Issue