From 9aa2b0b500a89969c34854f2ba5d0e550fadc250 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 7 Jan 2025 21:39:46 +0100 Subject: [PATCH 1/4] Edit tox.ini to match the versions in GHA. --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 9cabc12a..3a6335a8 100644 --- a/tox.ini +++ b/tox.ini @@ -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: From d96abb73fc50f035e1cd8229622ac0275330eae4 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 7 Jan 2025 21:41:48 +0100 Subject: [PATCH 2/4] requirements.txt: use zc.buildout 3.3. This works with all supported Python versions. With previous 3.0.1 I get an error on `tox -e plone60-py311`: ``` Requires-Python support missing and could not be patched into zc.buildout. Traceback (most recent call last): File "/Users/maurits/zest/irceline6/src/collective.exportimport/.tox/plone60-py311/lib/python3.11/site-packages/zc/buildout/patches.py", line 66, in patch_PackageIndex from pip._vendor import six ImportError: cannot import name 'six' from 'pip._vendor' (/Users/maurits/zest/irceline6/src/collective.exportimport/.tox/plone60-py311/lib/python3.11/site-packages/pip/_vendor/__init__.py) ``` `zc.buildout` swallows and accepts the error, but as the error says: Requires-Python support is then missing, and we would like to have it. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3f1fb9bb..2f75cfe5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 From 183f1d6a2058327e5d9ae0a189a1c022fd46ef47 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 7 Jan 2025 22:38:48 +0100 Subject: [PATCH 3/4] 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 https://github.com/collective/collective.exportimport/issues/247. --- CHANGES.rst | 5 ++ src/collective/exportimport/export_content.py | 14 ++++- .../exportimport/tests/test_export.py | 51 ++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 177d876e..ea0c8174 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,11 @@ Changelog 1.13 (unreleased) ----------------- +- 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 `_. + [maurits] + - Load code for exporting/importing comments conditionally. ``plone.app.discussion`` is optional since Plone 6.1. [maurits] diff --git a/src/collective/exportimport/export_content.py b/src/collective/exportimport/export_content.py index f5501feb..53ab6825 100644 --- a/src/collective/exportimport/export_content.py +++ b/src/collective/exportimport/export_content.py @@ -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) diff --git a/src/collective/exportimport/tests/test_export.py b/src/collective/exportimport/tests/test_export.py index b4daceb7..95c82479 100644 --- a/src/collective/exportimport/tests/test_export.py +++ b/src/collective/exportimport/tests/test_export.py @@ -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"] @@ -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) @@ -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"] From 39386f204967fd48e3c7b055df5bc4e8dac075e6 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 7 Jan 2025 22:47:31 +0100 Subject: [PATCH 4/4] Fix styling of export_content page in Plone 6.1. The checkbox inputs were displayed in block instead of inline with the label. --- CHANGES.rst | 4 ++++ src/collective/exportimport/templates/export_content.pt | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ea0c8174..8a086a18 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,10 @@ 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 `_. diff --git a/src/collective/exportimport/templates/export_content.pt b/src/collective/exportimport/templates/export_content.pt index 2b61501e..a7a9b19c 100644 --- a/src/collective/exportimport/templates/export_content.pt +++ b/src/collective/exportimport/templates/export_content.pt @@ -5,6 +5,9 @@ i18n:domain="collective.exportimport" metal:use-macro="context/main_template/macros/master"> +