Commit acf1401b authored by Yoshinori Okuji's avatar Yoshinori Okuji

This is the first attempt to make it possible to call setup with an existing site.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4870 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 92322417
...@@ -27,6 +27,8 @@ from Products.ERP5Type.Document import addFolder ...@@ -27,6 +27,8 @@ from Products.ERP5Type.Document import addFolder
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
from Products.ERP5Type import allowClassTool from Products.ERP5Type import allowClassTool
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5.Document.BusinessTemplate import BusinessTemplate
import ERP5Defaults import ERP5Defaults
from os import path from os import path
...@@ -106,6 +108,11 @@ class ERP5Site ( CMFSite, FolderMixIn ): ...@@ -106,6 +108,11 @@ class ERP5Site ( CMFSite, FolderMixIn ):
""" """
return self.index_html() return self.index_html()
def hasObject(self, id):
"""Check if the portal has an id.
"""
return id in self.objectIds()
security.declareProtected(Permissions.AccessContentsInformation, 'getPortalObject') security.declareProtected(Permissions.AccessContentsInformation, 'getPortalObject')
def getPortalObject(self): def getPortalObject(self):
return self return self
...@@ -663,16 +670,21 @@ class ERP5Generator(PortalGenerator): ...@@ -663,16 +670,21 @@ class ERP5Generator(PortalGenerator):
self.setup(p, create_userfolder,**kw) self.setup(p, create_userfolder,**kw)
return p return p
def setupLastTools(self, p,**kw): def setupLastTools(self, p, **kw):
"""Set up finals tools """Set up finals tools
We want to set the activity tool only at the end to We want to set the activity tool only at the end to
make sure that we do not put un the queue the full reindexation make sure that we do not put un the queue the full reindexation
""" """
# Add Activity Tool # Add Activity Tool
LOG('setupTools, kw',0,kw) #LOG('setupTools, kw',0,kw)
if kw.has_key('create_activities') and int(kw['create_activities'])==1: if kw.has_key('create_activities') and int(kw['create_activities'])==1:
if not p.hasObject('portal_activities'):
addTool = p.manage_addProduct['CMFActivity'].manage_addTool addTool = p.manage_addProduct['CMFActivity'].manage_addTool
addTool('CMF Activity Tool', None) # Allow user to select active/passive addTool('CMF Activity Tool', None) # Allow user to select active/passive
# Initialize Activities
portal_activities = getToolByName(p, 'portal_activities', None)
if portal_activities is not None:
portal_activities.manageClearActivities()
def setupTemplateTool(self, p, **kw): def setupTemplateTool(self, p, **kw):
"""Setup the Template Tool. Security must be set strictly. """Setup the Template Tool. Security must be set strictly.
...@@ -693,6 +705,8 @@ class ERP5Generator(PortalGenerator): ...@@ -693,6 +705,8 @@ class ERP5Generator(PortalGenerator):
# It is better to remove portal_catalog which is ZCatalog as soon as possible, # It is better to remove portal_catalog which is ZCatalog as soon as possible,
# because the API is not the completely same as ERP5Catalog, and ZCatalog is # because the API is not the completely same as ERP5Catalog, and ZCatalog is
# useless for ERP5 after all. # useless for ERP5 after all.
portal_catalog = getToolByName(p, 'portal_catalog', None)
if portal_catalog is not None and portal_catalog.meta_type != 'ZSQLCatalog':
p._delObject('portal_catalog') p._delObject('portal_catalog')
# Add CMF Report Tool # Add CMF Report Tool
...@@ -701,19 +715,30 @@ class ERP5Generator(PortalGenerator): ...@@ -701,19 +715,30 @@ class ERP5Generator(PortalGenerator):
# Add ERP5 Tools # Add ERP5 Tools
addTool = p.manage_addProduct['ERP5'].manage_addTool addTool = p.manage_addProduct['ERP5'].manage_addTool
if not p.hasObject('portal_categories'):
addTool('ERP5 Categories', None) addTool('ERP5 Categories', None)
if not p.hasObject('portal_rules'):
addTool('ERP5 Rule Tool', None) addTool('ERP5 Rule Tool', None)
if not p.hasObject('portal_ids'):
addTool('ERP5 Id Tool', None) addTool('ERP5 Id Tool', None)
if not p.hasObject('portal_simulation'):
addTool('ERP5 Simulation Tool', None) addTool('ERP5 Simulation Tool', None)
if not p.hasObject('portal_templates'):
self.setupTemplateTool(p) self.setupTemplateTool(p)
if not p.hasObject('portal_trash'):
addTool('ERP5 Trash Tool', None) addTool('ERP5 Trash Tool', None)
if not p.hasObject('portal_alarm'):
addTool('ERP5 Alarm Tool', None) addTool('ERP5 Alarm Tool', None)
if not p.hasObject('portal_domains'):
addTool('ERP5 Domain Tool', None) addTool('ERP5 Domain Tool', None)
if not p.hasObject('portal_deliveries'):
addTool('ERP5 Delivery Tool', None) addTool('ERP5 Delivery Tool', None)
if not p.hasObject('portal_orders'):
addTool('ERP5 Order Tool', None) addTool('ERP5 Order Tool', None)
# Add ERP5Type Tools # Add ERP5Type Tools
addTool = p.manage_addProduct['ERP5Type'].manage_addTool addTool = p.manage_addProduct['ERP5Type'].manage_addTool
if not p.hasObject('portal_classes'):
if allowClassTool(): if allowClassTool():
addTool('ERP5 Class Tool', None) addTool('ERP5 Class Tool', None)
else: else:
...@@ -721,20 +746,25 @@ class ERP5Generator(PortalGenerator): ...@@ -721,20 +746,25 @@ class ERP5Generator(PortalGenerator):
# Add ERP5 SQL Catalog Tool # Add ERP5 SQL Catalog Tool
addTool = p.manage_addProduct['ERP5Catalog'].manage_addTool addTool = p.manage_addProduct['ERP5Catalog'].manage_addTool
if not p.hasObject('portal_catalog'):
addTool('ERP5 Catalog', None) addTool('ERP5 Catalog', None)
# Add Default SQL connection # Add Default SQL connection
if p.erp5_sql_connection_type == 'Z MySQL Database Connection': if p.erp5_sql_connection_type == 'Z MySQL Database Connection':
if not p.hasObject('erp5_sql_connection'):
addSQLConnection = p.manage_addProduct['ZSQLMethods'].manage_addZMySQLConnection addSQLConnection = p.manage_addProduct['ZSQLMethods'].manage_addZMySQLConnection
addSQLConnection('erp5_sql_connection', 'ERP5 SQL Server Connection', p.erp5_sql_connection_string) addSQLConnection('erp5_sql_connection', 'ERP5 SQL Server Connection', p.erp5_sql_connection_string)
elif p.erp5_sql_connection_type == 'Z Gadfly': elif p.erp5_sql_connection_type == 'Z Gadfly':
pass pass
if p.cmf_activity_sql_connection_type == 'Z MySQL Database Connection': if p.cmf_activity_sql_connection_type == 'Z MySQL Database Connection':
if not p.hasObject('cmf_activity_sql_connection'):
addSQLConnection = p.manage_addProduct['ZSQLMethods'].manage_addZMySQLConnection addSQLConnection = p.manage_addProduct['ZSQLMethods'].manage_addZMySQLConnection
addSQLConnection('cmf_activity_sql_connection', 'CMF Activity SQL Server Connection', p.cmf_activity_sql_connection_string) addSQLConnection('cmf_activity_sql_connection', 'CMF Activity SQL Server Connection', p.cmf_activity_sql_connection_string)
elif p.cmf_activity_sql_connection_type == 'Z Gadfly': elif p.cmf_activity_sql_connection_type == 'Z Gadfly':
pass pass
# Create default methods in Catalog XXX # Create default methods in Catalog XXX
portal_catalog = getToolByName(p, 'portal_catalog') portal_catalog = getToolByName(p, 'portal_catalog')
if not portal_catalog.getSQLCatalog('erp5_mysql'):
# FIXME: addDefaultSQLMethods should be removed.
portal_catalog.addDefaultSQLMethods('erp5_mysql') portal_catalog.addDefaultSQLMethods('erp5_mysql')
# Clear Catalog # Clear Catalog
...@@ -742,11 +772,14 @@ class ERP5Generator(PortalGenerator): ...@@ -742,11 +772,14 @@ class ERP5Generator(PortalGenerator):
# Add ERP5Form Tools # Add ERP5Form Tools
addTool = p.manage_addProduct['ERP5Form'].manage_addTool addTool = p.manage_addProduct['ERP5Form'].manage_addTool
if not p.hasObject('portal_selections'):
addTool('ERP5 Selections', None) addTool('ERP5 Selections', None)
if not p.hasObject('portal_preferences'):
addTool('ERP5 Preference Tool', None) addTool('ERP5 Preference Tool', None)
# Add ERP5SyncML Tools # Add ERP5SyncML Tools
addTool = p.manage_addProduct['ERP5SyncML'].manage_addTool addTool = p.manage_addProduct['ERP5SyncML'].manage_addTool
if not p.hasObject('portal_synchronizations'):
addTool('ERP5 Synchronizations', None) addTool('ERP5 Synchronizations', None)
# Add Message Catalog # Add Message Catalog
...@@ -758,6 +791,7 @@ class ERP5Generator(PortalGenerator): ...@@ -758,6 +791,7 @@ class ERP5Generator(PortalGenerator):
addLocalizer('', ('en',)) addLocalizer('', ('en',))
localizer = getToolByName(p, 'Localizer') localizer = getToolByName(p, 'Localizer')
addMessageCatalog = localizer.manage_addProduct['Localizer'].manage_addMessageCatalog addMessageCatalog = localizer.manage_addProduct['Localizer'].manage_addMessageCatalog
if 'erp5_ui' not in localizer.objectIds():
if 'default' in localizer.objectIds(): if 'default' in localizer.objectIds():
localizer.manage_delObjects('default') localizer.manage_delObjects('default')
addMessageCatalog('default', 'ERP5 Localized Messages', ('en',)) addMessageCatalog('default', 'ERP5 Localized Messages', ('en',))
...@@ -765,8 +799,9 @@ class ERP5Generator(PortalGenerator): ...@@ -765,8 +799,9 @@ class ERP5Generator(PortalGenerator):
addMessageCatalog('erp5_content', 'ERP5 Localized Content', ('en',)) addMessageCatalog('erp5_content', 'ERP5 Localized Content', ('en',))
# Add Translation Service # Add Translation Service
if 'translation_service' in p.objectIds(): if p.hasObject('translation_service') and p.translation_service.meta_type != 'Translation Service':
p._delObject('translation_service') p._delObject('translation_service')
if not p.hasObject('translation_service'):
p.manage_addProduct['TranslationService'].addPlacefulTranslationService('translation_service') p.manage_addProduct['TranslationService'].addPlacefulTranslationService('translation_service')
p.translation_service.manage_setDomainInfo(domain_0=None, path_0='Localizer/default') p.translation_service.manage_setDomainInfo(domain_0=None, path_0='Localizer/default')
p.translation_service.manage_addDomainInfo(domain='ui', path='Localizer/erp5_ui') p.translation_service.manage_addDomainInfo(domain='ui', path='Localizer/erp5_ui')
...@@ -778,56 +813,6 @@ class ERP5Generator(PortalGenerator): ...@@ -778,56 +813,6 @@ class ERP5Generator(PortalGenerator):
ERP5 is not a CMS ERP5 is not a CMS
""" """
pass pass
#from Products.CMFDefault.MembershipTool import MembershipTool
#addFolder(p, id=MembershipTool.membersfolder_id, title='ERP5 Members')
#member_folder = p[MembershipTool.membersfolder_id]
#member_folder.manage_addProduct['OFSP'].manage_addDTMLMethod(
# 'index_html', 'Member list', '<dtml-return roster>')
def setupFrontPage(self, p):
text = """<span metal:define-macro="body">
<span tal:condition="python: not here.portal_membership.isAnonymousUser()">
<br/>
<br/>
<br/>
<br/>
<h2 align="center" i18n:translate="" i18n:domain="ui">
Welcome to ERP5
</h2>
<table border="1" align="center">
<tr tal:define="module_list python:here.ERP5Site_getModuleItemList();
module_len python:len(module_list);
col_size python:16;
col_len python:(module_len + col_size) / col_size">
<td>
<a href="http://www.erp5.org"><img src="images/erp5_logo.png" alt="ERP5 Logo" /></a>
</td>
<tal:block tal:repeat="col_no python:range(col_len)">
<td valign="top" class="ModuleShortcut">
<tal:block tal:repeat="module python:module_list[col_size*col_no:min(col_size*(col_no+1),module_len)] ">
<p>
<a href="person"
tal:content="python: module[0]"
tal:attributes="href python: module[1] + '/view'">
Person
</a>
</p>
</tal:block>
</td>
</tal:block>
</tr>
</table>
</span>
<span tal:condition="python: here.portal_membership.isAnonymousUser()">
<p tal:define="dummy python:request.RESPONSE.redirect('%s/login_form' % here.absolute_url())"/>
</span>
</span>
"""
p.manage_addProduct['PageTemplates'].manage_addPageTemplate(
'local_pt', title='ERP5 Front Page', text=text)
def setupDefaultSkins(self, p): def setupDefaultSkins(self, p):
from Products.CMFCore.DirectoryView import addDirectoryViews from Products.CMFCore.DirectoryView import addDirectoryViews
...@@ -866,6 +851,9 @@ class ERP5Generator(PortalGenerator): ...@@ -866,6 +851,9 @@ class ERP5Generator(PortalGenerator):
tool = getToolByName(p, 'portal_workflow', None) tool = getToolByName(p, 'portal_workflow', None)
if tool is None: if tool is None:
return return
for wf_id in ('business_template_building_workflow', 'business_template_installation_workflow'):
if wf_id in tool.objectIds():
tool.manage_delObjects([wf_id])
bootstrap_dir = self.getBootstrapDirectory() bootstrap_dir = self.getBootstrapDirectory()
business_template_building_workflow = os.path.join(bootstrap_dir, business_template_building_workflow = os.path.join(bootstrap_dir,
'business_template_building_workflow.xml') 'business_template_building_workflow.xml')
...@@ -879,21 +867,15 @@ class ERP5Generator(PortalGenerator): ...@@ -879,21 +867,15 @@ class ERP5Generator(PortalGenerator):
'business_template_installation_workflow' ) ) 'business_template_installation_workflow' ) )
pass pass
def setupIndex(self, p,**kw): def setupIndex(self, p, **kw):
from Products.CMFDefault.MembershipTool import MembershipTool
# Make sure all tools and folders have been indexed # Make sure all tools and folders have been indexed
portal_catalog = p.portal_catalog
portal_catalog.manage_catalogClear()
if kw.has_key('reindex') and kw['reindex']==0: if kw.has_key('reindex') and kw['reindex']==0:
return return
#portal_catalog.reindexObject(p)
#portal_catalog.reindexObject(p.portal_templates)
#portal_catalog.reindexObject(p.portal_categories)
# portal_catalog.reindexObject(p.portal_activities)
#p[MembershipTool.membersfolder_id].immediateReindexObject()
skins_tool = getToolByName(p, 'portal_skins', None) skins_tool = getToolByName(p, 'portal_skins', None)
if skins_tool is None: if skins_tool is None:
return return
portal_catalog = p.portal_catalog
portal_catalog.manage_catalogClear()
skins_tool["erp5_core"].ERP5Site_reindexAll() skins_tool["erp5_core"].ERP5Site_reindexAll()
def setupUserFolder(self, p): def setupUserFolder(self, p):
...@@ -973,54 +955,58 @@ class ERP5Generator(PortalGenerator): ...@@ -973,54 +955,58 @@ class ERP5Generator(PortalGenerator):
role_list = permission_dict.get(name, ('Manager',)) role_list = permission_dict.get(name, ('Manager',))
p.manage_permission(name, roles=role_list, acquire=0) p.manage_permission(name, roles=role_list, acquire=0)
def setup(self, p, create_userfolder,**kw): def setup(self, p, create_userfolder, **kw):
self.setupTools(p,**kw) update = kw.get('update', 0)
self.setupTools(p, **kw)
if not p.hasObject('MailHost'):
self.setupMailHost(p) self.setupMailHost(p)
if int(create_userfolder) != 0:
if int(create_userfolder) != 0 and not p.hasObject('acl_users'):
self.setupUserFolder(p) self.setupUserFolder(p)
if not p.hasObject('cookie_authentication'):
self.setupCookieAuth(p) self.setupCookieAuth(p)
if 'Member' not in getattr(p, '__ac_roles__', ()):
self.setupRoles(p) self.setupRoles(p)
if not update:
self.setupPermissions(p) self.setupPermissions(p)
self.setupDefaultSkins(p) self.setupDefaultSkins(p)
# Initialize Activities self.setupLastTools(p, **kw)
portal_skins = p.portal_skins
try:
portal_skins.activity.SQLDict_dropMessageTable()
portal_skins.activity.SQLQueue_dropMessageTable()
except:
pass
portal_skins.activity.SQLDict_createMessageTable()
portal_skins.activity.SQLQueue_createMessageTable()
self.setupLastTools(p,**kw)
# Finish setup # Finish setup
if not p.hasObject('Members'):
self.setupMembersFolder(p) self.setupMembersFolder(p)
# ERP5 Design Choice is that all content should be user defined # ERP5 Design Choice is that all content should be user defined
# Content is disseminated through business templates # Content is disseminated through business templates
self.setupBusinessTemplate(p) self.setupBusinessTemplate(p)
if not p.hasObject('content_type_registry'):
self.setupMimetypes(p) self.setupMimetypes(p)
self.setupWorkflow(p) self.setupWorkflow(p)
self.setupFrontPage(p)
if not update:
self.setupERP5Core(p,**kw) self.setupERP5Core(p,**kw)
# Make sure tools are cleanly indexed with a uid before creating children # Make sure tools are cleanly indexed with a uid before creating children
# XXX for some strange reason, member was indexed 5 times # XXX for some strange reason, member was indexed 5 times
self.setupIndex(p,**kw) if not update:
self.setupIndex(p, **kw)
def setupBusinessTemplate(self,p): def setupBusinessTemplate(self,p):
""" """
Install the portal_type of Business Template Install the portal_type of Business Template
""" """
from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5.Document.BusinessTemplate import BusinessTemplate
tool = getToolByName(p, 'portal_types', None) tool = getToolByName(p, 'portal_types', None)
if tool is None: if tool is None:
return return
if 'Business Template' not in tool.objectIds():
t = BusinessTemplate.factory_type_information t = BusinessTemplate.factory_type_information
ti = apply(ERP5TypeInformation, (), t) ti = apply(ERP5TypeInformation, (), t)
tool._setObject(t['id'], ti) tool._setObject(t['id'], ti)
...@@ -1032,6 +1018,7 @@ class ERP5Generator(PortalGenerator): ...@@ -1032,6 +1018,7 @@ class ERP5Generator(PortalGenerator):
template_tool = getToolByName(p, 'portal_templates', None) template_tool = getToolByName(p, 'portal_templates', None)
if template_tool is None: if template_tool is None:
return return
if template_tool.getInstalledBusinessTemplate('erp5_core') is None:
bootstrap_dir = self.getBootstrapDirectory() bootstrap_dir = self.getBootstrapDirectory()
template = os.path.join(bootstrap_dir, 'erp5_core') template = os.path.join(bootstrap_dir, 'erp5_core')
if not os.path.exists(template): if not os.path.exists(template):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment