Skip to content
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
38 changes: 37 additions & 1 deletion Products/zms/manage_addzmsform.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</a>
</span>
</div>
<div class="collapse" id="TAB_ADVANCED">
<div class="alert alert-info collapse" id="TAB_ADVANCED">
<div class="form-group px-4">
<label for="zcatalog_init_toggle" class="form-check-label m-0">
<!--! Hint: zcatalog_init-option needs a value 0|1 to control ZMSZCatalogAdapter.ensure_zcatalog_connector_is_initialized() -->
Expand All @@ -103,6 +103,42 @@
As Multisite-Client (acquiring configuration from existing parent node)
</label>
</div>
<hr class="my-4"/>
<div class="form-group form-inline mb-0"
title="Creates a multisite with the given depth and number of clients by recursively copying the root node as template for each client.">
<div class="input-group input-group-sm mb-3 pl-1">
<input class="form-check-input mr-2" type="checkbox" id="multisite_init" name="multisite_init:int" value="1"/>
<label for="multisite_init" class="input-group-append">
Create Multisite
</label>
</div>
<div class="input-group input-group-sm mb-3 mx-2">
<label for="multisite_depth" class="input-group-prepend">
<span class="input-group-text">Depth</span>
</label>
<input class="form-number-input form-control" type="number" id="multisite_depth"
name="multisite_depth:int" value="2" size="1" min="0" max="9" style="width:3rem" />
</div>
<div class="form-group form-inline mb-3">
<span>^</span>
</div>
<div class="input-group input-group-sm mb-3 mx-2">
<label for="multisite_clients" class="input-group-prepend">
<span class="input-group-text">Clients</span>
</label>
<input class="form-number-input form-control" type="number" id="multisite_clients"
name="multisite_clients:int" value="2" size="1" min="0" max="9" style="width:3rem" />
</div>
</div>
<small class="text-muted">
Note: The Multisite option is intended for testing and demonstration purposes.<br/>
Depending on the selected values and options, the creation of all
clients of the multisite may take a while
because the number of created nodes grows exponentially with the depth and
number of clients: <code>Total Nodes = (Clients^(Depth+1) - 1) / (Clients - 1)</code><br/>
<i>Example</i>: Depth=3 and Clients=3 will create 1 root node with 3 clients, each client
will have 3 sub-clients and each sub-client will have 3 sub-sub-clients (total 40 nodes).
</small>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Products/zms/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def initZMS(self, id, titlealt, title, lang, manage_lang, REQUEST):
##### Add ZMS ####
from Products.zms import zms
content = zms.initZMS(homeElmnt, 'content', titlealt, title, lang, manage_lang, REQUEST)
zms.initContent(content, 'content.default.zip', REQUEST)
zms.init_content(content, 'content.default.zip', REQUEST)

return content

Expand Down
2 changes: 1 addition & 1 deletion Products/zms/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.0+8de27ea
6.0.0+3ba5090
57 changes: 53 additions & 4 deletions Products/zms/zms.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def initZMS(self, id, titlealt, title, lang, manage_lang, REQUEST, minimal_init
master = hasattr(self.aq_parent,'content') and (self.aq_parent.content or self.aq_parent.content.getPortalMaster()) or None
if master:
obj.setConfProperty('Portal.Master',master.getHome().id)
master.setConfProperty('Portal.Clients', master.getConfProperty('Portal.Clients', []) + [self.id])
masterMetaObjIds_ignore = ['ZMSIndexZCatalog','com.zms.index'] # Ignore obsolete object classes.
if REQUEST.get('zcatalog_init', 0) == 0:
masterMetaObjIds_ignore.extend(['com.zms.catalog.zcatalog','zcatalog_connector','zcatalog_page'])
Expand Down Expand Up @@ -230,8 +231,19 @@ def initZMS(self, id, titlealt, title, lang, manage_lang, REQUEST, minimal_init

return obj


def initContent(self, filename, REQUEST):
def createZMS(context, id, name, REQUEST):
# Create the folder that contains the new client root.
print('[DEBUG] createZMS', id, name)
home = Folder(id)
context._setObject(home.id, home)
home = [x for x in context.objectValues() if x.id == home.id][0]
lang = REQUEST['lang']
manage_lang = REQUEST['manage_lang']
titlealt = '%s home'%name
title = '%s - Python-based Content Management System for Science, Technology and Medicine'%name
return initZMS(home, 'content', titlealt, title, lang, manage_lang, REQUEST)

def init_content(self, filename, REQUEST):
"""
Import initial site content from a bundled archive.

Expand All @@ -246,9 +258,37 @@ def initContent(self, filename, REQUEST):
_importable.importFile( self, file, REQUEST, _importable.importContent)


manage_addZMSForm = PageTemplateFile('manage_addzmsform', globals())
def init_multisite(zms, depth, clients, prefix='client', REQUEST=None):
"""
Initialize a multisite content structure with the given depth and number of clients.

@param zms: ZMS site that receives the multisite content structure.
@param depth: Depth of the multisite folder hierarchy.
@param clients: Number of client folders at each level.
@param REQUEST: Active HTTP request.
"""
lang = REQUEST['lang']
for i in range(clients):
# Create client site that acquires from the portal master.
id = '%s%i'%(prefix,i)
name = id.capitalize()
print('[DEBUG] init_multisite', id, name, depth, clients, prefix)
home = zms.getHome()
REQUEST.set('acquire', 1)
content = createZMS(home, id, name, REQUEST)
if REQUEST.get('content_init', 0)==1:
# Init content
init_content(content, 'content.default.zip', REQUEST)
# Restore title and titlealt after content import.
titlealt = '%s home'%name
title = '%s - Python-based Content Management System for Science, Technology and Medicine'%name
content.setObjProperty('titlealt', titlealt, lang)
content.setObjProperty('title', title, lang)
if depth > 0:
init_multisite(content, depth-1, clients, id, REQUEST=REQUEST)


manage_addZMSForm = PageTemplateFile('manage_addzmsform', globals())
def manage_addZMS(self, lang, manage_lang, REQUEST, RESPONSE):
"""
Create the top-level home folder and initial ZMS site from the add form.
Expand Down Expand Up @@ -285,7 +325,16 @@ def manage_addZMS(self, lang, manage_lang, REQUEST, RESPONSE):
obj.setConfProperty('ZMS.theme',theme_id.replace('.','_'))

if REQUEST.get('content_init', 0)==1:
initContent(obj, 'content.default.zip', REQUEST)
init_content(obj, 'content.default.zip', REQUEST)

if REQUEST.get('multisite_init', 0)==1:
# Initialize multisite content structure with the given depth
# and number of clients. The depth is reduced by one because
# the first level of the multisite structure is already created
# at this point (the newly created site).
depth = max(int(REQUEST.get('multisite_depth', 1))-1,0)
clients = int(REQUEST.get('multisite_clients', 0))
init_multisite(obj, depth, clients, REQUEST=REQUEST)

# Initialize catalog adapter / connector.
if REQUEST.get('zcatalog_init', 0)==1:
Expand Down
Loading