Skip to content

Commit 28f2eb0

Browse files
committed
rework for readability
1 parent b4a3506 commit 28f2eb0

3 files changed

Lines changed: 73 additions & 53 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Changelog
55
1.16 (unreleased)
66
-----------------
77

8-
- Skip setting a default page if the default is already set to the same value.
8+
- Skip setting a default page if the default is already set to the same value.
99
[mamico]
1010
- Fixed data extraction of Archetypes ATFilefields to concatenate all `Pdata` chunks, when the FileField data was still stored in Filestorage and not not migrated to use blobstorage (using plone.app.blobs).
1111
[@jnptk]
1212
- Bugfix to prevent clearing existing relations from catalog when migrating into sites with existing content [ThibautBorn]
13-
- Add option to export portal settings (local roles, default pages, portlets) [ThibautBorn]
13+
- Enable option to not export the portal settings (local roles, default pages, portlets) [ThibautBorn]
1414

1515
1.15 (2025-07-15)
1616
-----------------

src/collective/exportimport/export_other.py

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from zope.component import getUtility
3131
from zope.component import queryMultiAdapter
3232
from zope.component import queryUtility
33+
from zope.deprecation import deprecation
3334
from zope.interface import providedBy
3435

3536
import json
@@ -86,7 +87,7 @@
8687
class BaseExport(BrowserView):
8788
"""Just DRY"""
8889

89-
show_root_export_option = False
90+
show_export_portal_option = False
9091

9192
def download(self, data):
9293
filename = self.request.form.get("filename")
@@ -429,27 +430,31 @@ def all_translations(self): # noqa: C901
429430
class ExportLocalRoles(BaseExport):
430431
"""Export all local roles"""
431432

432-
show_root_export_option = True
433+
show_export_portal_option = True
433434

434-
def __call__(self, download_to_server=False, exclude_root_settings=False):
435+
# Because an unticked HTML checkbox is not included in the HTTP request,
436+
# the default (ie not present) value has to be False.
437+
# This mandates exclude_portal=False instead of more readable export_portal=True.
438+
def __call__(self, download_to_server=False, exclude_portal=False):
435439
self.title = _(u"Export local roles")
436440
self.download_to_server = download_to_server
437441
if not self.request.form.get("form.submitted", False):
438442
return self.index()
439443

440444
logger.info(u"Exporting local roles...")
441-
data = self.all_localroles(exclude_root_settings)
445+
export_portal = not exclude_portal
446+
data = self.all_localroles(export_portal)
442447
logger.info(u"Exported local roles for %s items", len(data))
443448
self.download(data)
444449

445-
def all_localroles(self, exclude_root_settings=False):
450+
def all_localroles(self, export_portal=True):
446451
self.results = []
447452

448453
portal = api.portal.get()
449454
portal.ZopeFindAndApply(portal, search_sub=True, apply_func=self.get_localroles)
450455

451-
if not exclude_root_settings:
452-
self.get_root_localroles()
456+
if export_portal:
457+
self.get_portal_localroles()
453458

454459
return self.results
455460

@@ -478,10 +483,12 @@ def _get_localroles(self, obj, uid):
478483
return
479484
self.results.append(item)
480485

481-
def get_root_localroles(self):
486+
def get_portal_localroles(self):
482487
site = api.portal.get()
483488
self._get_localroles(site, PORTAL_PLACEHOLDER)
484489

490+
get_root_localroles = deprecation.deprecated(get_portal_localroles, 'get_root_localroles renamed to get_portal_localroles')
491+
485492
def item_hook(self, item):
486493
return item
487494

@@ -525,20 +532,24 @@ def get_position_in_parent(obj, path):
525532
class ExportDefaultPages(BaseExport):
526533
"""Export all default_page settings."""
527534

528-
show_root_export_option = True
535+
show_export_portal_option = True
529536

530-
def __call__(self, download_to_server=False, exclude_root_settings=False):
537+
# Because an unticked HTML checkbox is not included in the HTTP request,
538+
# the default (ie not present) value has to be False.
539+
# This mandates exclude_portal=False instead of more readable export_portal=True.
540+
def __call__(self, download_to_server=False, exclude_portal=False):
531541
self.title = _(u"Export default pages")
532542
self.download_to_server = download_to_server
533543
if not self.request.form.get("form.submitted", False):
534544
return self.index()
535545

536546
logger.info(u"Exporting default pages...")
537-
data = self.all_default_pages(exclude_root_settings)
547+
export_portal = not exclude_portal
548+
data = self.all_default_pages(export_portal)
538549
logger.info(u"Exported %s default pages", len(data))
539550
self.download(data)
540551

541-
def all_default_pages(self, exclude_root_settings=False):
552+
def all_default_pages(self, export_portal=True):
542553
results = []
543554
catalog = api.portal.get_tool("portal_catalog")
544555
for brain in catalog.unrestrictedSearchResults(
@@ -553,11 +564,11 @@ def all_default_pages(self, exclude_root_settings=False):
553564
logger.error(u"brain.getObject() is None %s", brain.getPath())
554565
continue
555566
if IPloneSiteRoot.providedBy(obj):
556-
# Site root is handled below (in Plone 6 it is returned by a catalog search)
567+
# Portal is handled below (in Plone 6 it is returned by a catalog search)
557568
continue
558569

559570
try:
560-
data = self.get_default_page_info(obj)
571+
data = get_default_page_info(obj)
561572
except Exception:
562573
logger.info(
563574
u"Error exporting default_page for %s",
@@ -570,40 +581,43 @@ def all_default_pages(self, exclude_root_settings=False):
570581
results.append(data)
571582

572583
# handle portal
573-
if not exclude_root_settings:
584+
if export_portal:
574585
portal = api.portal.get()
575586
try:
576-
data = self.get_default_page_info(portal)
577-
if data:
578-
data["uuid"] = config.SITE_ROOT
579-
results.append(data)
587+
portal_data = get_default_page_info(portal)
588+
if portal_data:
589+
portal_data["uuid"] = config.SITE_ROOT
590+
results.append(portal_data)
580591
except Exception:
581592
logger.info(u"Error exporting default_page for portal", exc_info=True)
582-
583593
return results
584594

585595
def get_default_page_info(self, obj):
586-
uid = IUUID(obj, None)
596+
return get_default_page_info(obj)
587597

588-
# We use a simplified method to only get index_html
589-
# and the property default_page on the object.
590-
# We don't care about other cases
591-
# 1. obj is folderish, check for a index_html in it
592-
if "index_html" in obj:
593-
default_page = "index_html"
594-
else:
595-
# 2. Check attribute 'default_page'
596-
default_page = getattr(aq_base(obj), "default_page", [])
597-
598-
if default_page and default_page in obj:
599-
default_page_obj = obj.get(default_page)
600-
if default_page_obj:
601-
default_page_uid = IUUID(default_page_obj, None)
602-
return {
603-
"uuid": uid,
604-
"default_page": default_page,
605-
"default_page_uuid": default_page_uid,
606-
}
598+
599+
def get_default_page_info(obj):
600+
uid = IUUID(obj, None)
601+
602+
# We use a simplified method to only get index_html
603+
# and the property default_page on the object.
604+
# We don't care about other cases
605+
# 1. obj is folderish, check for a index_html in it
606+
if "index_html" in obj:
607+
default_page = "index_html"
608+
else:
609+
# 2. Check attribute 'default_page'
610+
default_page = getattr(aq_base(obj), "default_page", [])
611+
612+
if default_page and default_page in obj:
613+
default_page_obj = obj.get(default_page)
614+
if default_page_obj:
615+
default_page_uid = IUUID(default_page_obj, None)
616+
return {
617+
"uuid": uid,
618+
"default_page": default_page,
619+
"default_page_uuid": default_page_uid,
620+
}
607621

608622

609623
if HAS_DISCUSSION: # noqa: C901
@@ -651,28 +665,32 @@ def all_discussions(self):
651665

652666
class ExportPortlets(BaseExport):
653667

654-
show_root_export_option = True
668+
show_export_portal_option = True
655669

656-
def __call__(self, download_to_server=False, exclude_root_settings=False):
670+
# Because an unticked HTML checkbox is not included in the HTTP request,
671+
# the default (ie not present) value has to be False.
672+
# This mandates exclude_portal=False instead of more readable export_portal=True.
673+
def __call__(self, download_to_server=False, exclude_portal=False):
657674
self.title = _(u"Export portlets")
658675
self.download_to_server = download_to_server
659676
if not self.request.form.get("form.submitted", False):
660677
return self.index()
661678

662679
logger.info(u"Exporting portlets...")
663-
data = self.all_portlets(exclude_root_settings)
680+
export_portal = not exclude_portal
681+
data = self.all_portlets(export_portal)
664682
logger.info(u"Exported info for %s items with portlets", len(data))
665683
self.download(data)
666684

667-
def all_portlets(self, exclude_root_settings=False):
685+
def all_portlets(self, export_portal=True):
668686
self.results = []
669687
portal = api.portal.get()
670688
portal.ZopeFindAndApply(
671689
self.context, search_sub=True, apply_func=self.get_portlets
672690
)
673691

674-
if not exclude_root_settings:
675-
self.get_root_portlets()
692+
if export_portal:
693+
self.get_portal_portlets()
676694

677695
return self.results
678696

@@ -698,11 +716,13 @@ def _get_portlets(self, obj, uid):
698716
self.results.append(obj_results)
699717
return
700718

701-
def get_root_portlets(self):
719+
def get_portal_portlets(self):
702720
site = api.portal.get()
703721
self._get_portlets(site, PORTAL_PLACEHOLDER)
704722
return
705723

724+
get_root_portlets = deprecation.deprecated(get_portal_portlets, 'get_root_portlets renamed get_portal_portlets')
725+
706726
def local_portlets_hook(self, portlets):
707727
return portlets
708728

src/collective/exportimport/templates/export_other.pt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
</h1>
1414

1515
<form action="@@export_other" tal:attributes="action request/URL" method="post" enctype="multipart/form-data">
16-
<div class="field mb-3" tal:condition="python: getattr(view, 'show_root_export_option', False)">
16+
<div class="field mb-3" tal:condition="python: getattr(view, 'show_export_portal_option', False)">
1717
<div class="form-check">
18-
<input class="form-check-input" type="checkbox" name="exclude_root_settings:boolean" id="exclude_root">
19-
<label for="exclude_root" class="form-check-label" i18n:translate="">
18+
<input class="form-check-input" type="checkbox" name="exclude_portal:boolean" id="exclude_portal">
19+
<label for="exclude_portal" class="form-check-label" i18n:translate="">
2020
Do not export portal settings.
2121
<span class="formHelp" i18n:translate="">
2222
When you have exported a folder, instead of the entire portal.
@@ -26,7 +26,7 @@
2626
<hr>
2727
</div>
2828

29-
<div class="field mb-3">
29+
<div class="field mb-3">
3030
<div class="form-check">
3131
<input class="form-check-input" type="radio" name="download_to_server:int" value="0" id="download_local" checked="checked">
3232
<label for="download_local" class="form-check-label" i18n:translate="">

0 commit comments

Comments
 (0)