Skip to content

Commit ed73974

Browse files
committed
Configure option to export root settings
context: Some root settings are now exported & imported by default. Which might cause issues when migrating into an existing site. Allow users to chose if they need root settings.
1 parent 32ae130 commit ed73974

2 files changed

Lines changed: 47 additions & 19 deletions

File tree

src/collective/exportimport/export_other.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
class BaseExport(BrowserView):
8787
"""Just DRY"""
8888

89+
show_root_export_option = False
90+
8991
def download(self, data):
9092
filename = self.request.form.get("filename")
9193
if not filename:
@@ -427,24 +429,27 @@ def all_translations(self): # noqa: C901
427429
class ExportLocalRoles(BaseExport):
428430
"""Export all local roles"""
429431

430-
def __call__(self, download_to_server=False):
432+
show_root_export_option = True
433+
434+
def __call__(self, download_to_server=False, exclude_root_settings=False):
431435
self.title = _(u"Export local roles")
432436
self.download_to_server = download_to_server
433437
if not self.request.form.get("form.submitted", False):
434438
return self.index()
435439

436440
logger.info(u"Exporting local roles...")
437-
data = self.all_localroles()
441+
data = self.all_localroles(exclude_root_settings)
438442
logger.info(u"Exported local roles for %s items", len(data))
439443
self.download(data)
440444

441-
def all_localroles(self):
445+
def all_localroles(self, exclude_root_settings=False):
442446
self.results = []
443447

444448
portal = api.portal.get()
445449
portal.ZopeFindAndApply(portal, search_sub=True, apply_func=self.get_localroles)
446450

447-
self.get_root_localroles()
451+
if not exclude_root_settings:
452+
self.get_root_localroles()
448453

449454
return self.results
450455

@@ -520,18 +525,20 @@ def get_position_in_parent(obj, path):
520525
class ExportDefaultPages(BaseExport):
521526
"""Export all default_page settings."""
522527

523-
def __call__(self, download_to_server=False):
528+
show_root_export_option = True
529+
530+
def __call__(self, download_to_server=False, exclude_root_settings=False):
524531
self.title = _(u"Export default pages")
525532
self.download_to_server = download_to_server
526533
if not self.request.form.get("form.submitted", False):
527534
return self.index()
528535

529536
logger.info(u"Exporting default pages...")
530-
data = self.all_default_pages()
537+
data = self.all_default_pages(exclude_root_settings)
531538
logger.info(u"Exported %s default pages", len(data))
532539
self.download(data)
533540

534-
def all_default_pages(self):
541+
def all_default_pages(self, exclude_root_settings=False):
535542
results = []
536543
catalog = api.portal.get_tool("portal_catalog")
537544
for brain in catalog.unrestrictedSearchResults(
@@ -563,14 +570,15 @@ def all_default_pages(self):
563570
results.append(data)
564571

565572
# handle portal
566-
portal = api.portal.get()
567-
try:
568-
data = self.get_default_page_info(portal)
569-
if data:
570-
data["uuid"] = config.SITE_ROOT
571-
results.append(data)
572-
except Exception:
573-
logger.info(u"Error exporting default_page for portal", exc_info=True)
573+
if not exclude_root_settings:
574+
portal = api.portal.get()
575+
try:
576+
data = self.get_default_page_info(portal)
577+
if data:
578+
data["uuid"] = config.SITE_ROOT
579+
results.append(data)
580+
except Exception:
581+
logger.info(u"Error exporting default_page for portal", exc_info=True)
574582

575583
return results
576584

@@ -642,24 +650,30 @@ def all_discussions(self):
642650

643651

644652
class ExportPortlets(BaseExport):
645-
def __call__(self, download_to_server=False):
653+
654+
show_root_export_option = True
655+
656+
def __call__(self, download_to_server=False, exclude_root_settings=False):
646657
self.title = _(u"Export portlets")
647658
self.download_to_server = download_to_server
648659
if not self.request.form.get("form.submitted", False):
649660
return self.index()
650661

651662
logger.info(u"Exporting portlets...")
652-
data = self.all_portlets()
663+
data = self.all_portlets(exclude_root_settings)
653664
logger.info(u"Exported info for %s items with portlets", len(data))
654665
self.download(data)
655666

656-
def all_portlets(self):
667+
def all_portlets(self, exclude_root_settings=False):
657668
self.results = []
658669
portal = api.portal.get()
659670
portal.ZopeFindAndApply(
660671
self.context, search_sub=True, apply_func=self.get_portlets
661672
)
662-
self.get_root_portlets()
673+
674+
if not exclude_root_settings:
675+
self.get_root_portlets()
676+
663677
return self.results
664678

665679
def get_portlets(self, obj, path):

src/collective/exportimport/templates/export_other.pt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
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: view.show_root_export_option">
17+
<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="">
20+
Do not export portal settings.
21+
<span class="formHelp" i18n:translate="">
22+
When you have exported a folder, instead of the entire portal.
23+
</span>
24+
</label>
25+
</div>
26+
<hr>
27+
</div>
28+
:q
1629
<div class="field mb-3">
1730
<div class="form-check">
1831
<input class="form-check-input" type="radio" name="download_to_server:int" value="0" id="download_local" checked="checked">
@@ -28,6 +41,7 @@
2841
</div>
2942
</div>
3043

44+
3145
<div class="formControls" class="form-group">
3246
<button class="btn btn-primary submit-widget button-field context"
3347
type="submit" name="form.submitted" value="Export" tal:content="python: view.title" i18n:attributes="value" i18n:translate="">Export

0 commit comments

Comments
 (0)