Commit 66c1b8fd authored by Jérome Perrin's avatar Jérome Perrin

configurator: install business templates in one transaction

It's faster
parent 49774c8d
...@@ -32,14 +32,13 @@ from Products.ERP5Type import Permissions, PropertySheet ...@@ -32,14 +32,13 @@ from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from erp5.component.mixin.ConfiguratorItemMixin import ConfiguratorItemMixin from erp5.component.mixin.ConfiguratorItemMixin import ConfiguratorItemMixin
from erp5.component.interface.IConfiguratorItem import IConfiguratorItem from erp5.component.interface.IConfiguratorItem import IConfiguratorItem
from Products.ERP5Type.Cache import CachingMethod
from zLOG import LOG, INFO from zLOG import LOG, INFO
@zope.interface.implementer(IConfiguratorItem) @zope.interface.implementer(IConfiguratorItem)
class StandardBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject): class StandardBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject):
""" This class will install standard ERP5 template from a repository to """Install standard ERP5 business template from a repository
fake site. """ """
meta_type = 'ERP5 Standard BT5 Configurator Item' meta_type = 'ERP5 Standard BT5 Configurator Item'
portal_type = 'Standard BT5 Configurator Item' portal_type = 'Standard BT5 Configurator Item'
...@@ -61,29 +60,32 @@ class StandardBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject): ...@@ -61,29 +60,32 @@ class StandardBT5ConfiguratorItem(ConfiguratorItemMixin, XMLObject):
def _checkConsistency(self, fixit=False, **kw): def _checkConsistency(self, fixit=False, **kw):
template_tool = self.getPortalObject().portal_templates template_tool = self.getPortalObject().portal_templates
bt5_id = self.getBt5Id().split('.')[0]
if bt5_id in template_tool.getInstalledBusinessTemplateTitleList(): bt5_id_list = self.getBt5IdList()
# BBB this used to be a string property
if isinstance(bt5_id_list, str):
bt5_id_list = [bt5_id_list]
bt5_id_set = {bt.split('.')[0] for bt in bt5_id_list}
if not bt5_id_set.difference(template_tool.getInstalledBusinessTemplateTitleList()):
LOG("StandardBT5ConfiguratorItem", INFO, LOG("StandardBT5ConfiguratorItem", INFO,
"Business Template already Installed: %s for %s" % (bt5_id, self.getRelativeUrl())) "Business Templates already Installed: %s for %s" % (bt5_id_set, self.getRelativeUrl()))
return [] return []
def _getRepositoryBusinessTemplateTitleList(): repository_bt_title_set = {bt.getTitle() for bt in \
return [bt.getTitle() for bt in \ template_tool.getRepositoryBusinessTemplateList()}
template_tool.getRepositoryBusinessTemplateList()]
repository_bt_title_list = CachingMethod(
_getRepositoryBusinessTemplateTitleList,
id='StandardBT5_getRepositoryBusinessTemplateTitleList',
cache_factory='erp5_content_long')()
if bt5_id in repository_bt_title_list: not_found_bt_set = bt5_id_set.difference(repository_bt_title_set)
if not_found_bt_set:
raise ValueError("Business template %s not found on available \
sources." % not_found_bt_set)
if fixit: if fixit:
template_tool.installBusinessTemplateListFromRepository([bt5_id], template_tool.installBusinessTemplateListFromRepository(
list(bt5_id_set),
update_catalog=self.getUpdateCatalog(0), update_catalog=self.getUpdateCatalog(0),
install_dependency=self.getInstallDependency(1), install_dependency=self.getInstallDependency(1),
activate=True) activate=True)
return [self._createConstraintMessage('%s should be installed' % bt5_id),] return [self._createConstraintMessage('%s should be installed' % bt5_id_list),]
raise ValueError("The business template %s was not found on available \
sources." % bt5_id)
...@@ -19,11 +19,10 @@ bt5_installation_list = ('erp5_dhtml_style', ...@@ -19,11 +19,10 @@ bt5_installation_list = ('erp5_dhtml_style',
'erp5_osoe_web_renderjs_ui', 'erp5_osoe_web_renderjs_ui',
) )
bt5_update_catalog = ('erp5_ingestion_mysql_innodb_catalog', 'erp5_accounting', ) configuration_save.addConfigurationItem(
"Standard BT5 Configurator Item",
for name in bt5_installation_list: title="Standard business templates",
configuration_save.addConfigurationItem("Standard BT5 Configurator Item", bt5_id_list=bt5_installation_list,
title=name, bt5_id=name, update_catalog=True,
update_catalog=(name in bt5_update_catalog),
install_dependency=True, install_dependency=True,
) )
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<key> <string>categories</string> </key> <key> <string>categories</string> </key>
<value> <value>
<tuple> <tuple>
<string>elementary_type/string</string> <string>elementary_type/lines</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -43,13 +43,17 @@ ...@@ -43,13 +43,17 @@
<key> <string>mode</string> </key> <key> <string>mode</string> </key>
<value> <string>w</string> </value> <value> <string>w</string> </value>
</item> </item>
<item>
<key> <string>multivalued</string> </key>
<value> <int>0</int> </value>
</item>
<item> <item>
<key> <string>portal_type</string> </key> <key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value> <value> <string>Standard Property</string> </value>
</item> </item>
<item> <item>
<key> <string>property_default</string> </key> <key> <string>property_default</string> </key>
<value> <string>python: \'erp5_base\'</string> </value> <value> <string>python: (\'erp5_base\', )</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
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