Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 247, migration was always true. #250

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Changelog
1.13 (unreleased)
-----------------

- Fix styling of ``export_content`` page in Plone 6.1.
The checkbox inputs were displayed in block instead of inline with the label.
[maurits]

- Make it possible to switch off changing data for migration.
Previous, you could uncheck this checkbox in ``export_content``, but this was ignored.
This fixes `issue 247 <https://github.com/collective/collective.exportimport/issues/247>`_.
[maurits]

- Load code for exporting/importing comments conditionally.
``plone.app.discussion`` is optional since Plone 6.1.
[maurits]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# For Buildout related packages, it is easiest to keep them at the same version for all environments.
# Keep these in sync with base.cfg please:
zc.buildout==3.0.1
zc.buildout==3.3
# setuptools 67 is too strict with versions
setuptools<67
14 changes: 12 additions & 2 deletions src/collective/exportimport/export_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,24 @@ def __call__(
depth=-1,
include_blobs=1,
download_to_server=False,
migration=True,
migration=False,
include_revisions=False,
write_errors=False,
):
self.portal_type = portal_type or []
if isinstance(self.portal_type, str):
self.portal_type = [self.portal_type]
self.migration = migration

# Should we adapt the data for migration?
# We had migration=True by default at first. Problem is that when you
# uncheck the migration box in the form, it does not end up in the
# request, so migration would still be True. See
# https://github.com/collective/collective.exportimport/issues/247
if self.request.method == "GET":
# By default we want this, so on initial page load we make it true.
self.migration = True
else:
self.migration = migration
self.path = path or "/".join(self.context.getPhysicalPath())

self.depth = int(depth)
Expand Down
3 changes: 3 additions & 0 deletions src/collective/exportimport/templates/export_content.pt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
i18n:domain="collective.exportimport"
metal:use-macro="context/main_template/macros/master">

<style metal:fill-slot="style_slot">
label input { display: inline-block };
</style>
<div metal:fill-slot="main">
<tal:main-macro metal:define-macro="main">

Expand Down
51 changes: 50 additions & 1 deletion src/collective/exportimport/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_export_content_page(self):
with self.assertRaises(LookupError):
browser.getControl(name="portal_type")

def test_export_content_document(self):
def test_export_content_document_with_migration(self):
# First create some content.
app = self.layer["app"]
portal = self.layer["portal"]
Expand All @@ -112,6 +112,7 @@ def test_export_content_document(self):

# Now export Documents.
browser = self.open_page("@@export_content")
self.assertTrue(browser.getControl(name="migration:boolean").value)
portal_type = browser.getControl(name="portal_type")
self.assertEqual(portal_type.value, [])
self.assertIn("Document", portal_type.options)
Expand All @@ -137,6 +138,54 @@ def test_export_content_document(self):
self.assertEqual(info["@type"], "Document")
self.assertEqual(info["title"], doc.Title())

# By default, we adapt the data for migration. This means some data
# from the standard REST API call should not be there.
keys = sorted(info.keys())
self.assertNotIn(u"@components", keys)
self.assertNotIn(u"next_item", keys)

def test_export_content_document_without_migration(self):
# First create some content.
app = self.layer["app"]
portal = self.layer["portal"]
login(app, SITE_OWNER_NAME)
doc = api.content.create(
container=portal, type="Document", id="doc1", title="Document 1"
)
transaction.commit()

# Now export Documents.
browser = self.open_page("@@export_content")
# Here is the difference with the previous test method:
# do not adapt the data for migration.
browser.getControl(name="migration:boolean").value = False
portal_type = browser.getControl(name="portal_type")
portal_type.value = ["Document"]
try:
# Plone 5.2
browser.getForm(action="@@export_content").submit(name="submit")
except LookupError:
# Plone 5.1 and lower
browser.getForm(index=1).submit()
contents = browser.contents
if not browser.contents:
contents = DATA[-1]

# We should have gotten json.
data = json.loads(contents)
self.assertEqual(len(data), 1)

# Some important keys should still be there.
info = data[0]
self.assertEqual(info["@id"], portal.absolute_url() + "/doc1")
self.assertEqual(info["@type"], "Document")
self.assertEqual(info["title"], doc.Title())

# Now all the standard REST API keys should be there.
keys = sorted(info.keys())
self.assertIn(u"@components", keys)
self.assertIn(u"next_item", keys)

def test_export_collection(self):
# First create some content.
app = self.layer["app"]
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist =
plone50-py27
plone51-py27
plone52-py{27,36,37,38}
plone60-py{38,39}
plone60-py{39,310,311}

[testenv]
# We do not install with pip, but with buildout:
Expand Down