[Erp5-report] r11878 - /erp5/trunk/products/ERP5/Document/BusinessTemplate.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Jan 3 16:43:49 CET 2007
Author: vincent
Date: Wed Jan 3 16:43:44 2007
New Revision: 11878
URL: http://svn.erp5.org?rev=11878&view=rev
Log:
Add an extra check on meta_type before automaticaly creating an SQLCatalog.
Add code to remove SQLCatalog instance when all content has been uninstalled.
Do not get/set SQLCatalog properties on portal_catalog.getSQLCatalog() (which is the default catalog) but on the catalog corresponding to the ZSQLMethods being worked with. Thiw adds a limitation on business templates : all ZSQLMethods in a given business template must belong to the same SQLCatalog.
Remove an extra (useless) default catalog gathering.
Add dependency checking before business template preinstall and install.
Modified:
erp5/trunk/products/ERP5/Document/BusinessTemplate.py
Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=11878&r1=11877&r2=11878&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py Wed Jan 3 16:43:44 2007
@@ -90,6 +90,32 @@
'_filter_expression_instance_archive',
'_filter_type_archive',)
+def _getCatalog(acquisition_context):
+ """
+ Return the id of the SQLCatalog which correspond to the current BT.
+ """
+ catalog_method_id_list = acquisition_context.getTemplateCatalogMethodIdList()
+ if len(catalog_method_id_list) == 0:
+ return None
+ catalog_method_id = catalog_method_id_list[0]
+ return catalog_method_id.split('/')[0]
+
+def _getCatalogValue(acquisition_context):
+ """
+ Returns the catalog object which correspond to the ZSQLMethods
+ stored/to store in the business template.
+
+ NB: acquisition_context must make possible to reach portal object
+ and getTemplateCatalogMethodIdList.
+ """
+ catalog_id = _getCatalog(acquisition_context)
+ if catalog_id is None:
+ return None
+ try:
+ return acquisition_context.getPortalObject().portal_catalog[catalog_id]
+ except KeyError:
+ return None
+
def removeAll(entry):
'''
Remove all files and directories under 'entry'.
@@ -583,11 +609,14 @@
# If container's container is portal_catalog,
# then automatically create the container.
elif container_path[-2] == 'portal_catalog':
+ # The id match, but better double check with the meta type
+ # while avoiding the impact of systematic check
container_container = portal.unrestrictedTraverse(container_path[:-1])
- container_container.manage_addProduct['ZSQLCatalog'].manage_addSQLCatalog(id=container_path[-1], title='')
- if len(container_container.objectIds()) == 1:
- container_container.default_sql_catalog_id = container_path[-1]
- container = portal.unrestrictedTraverse(container_path)
+ if container_container.meta_type == 'ERP5 Catalog':
+ container_container.manage_addProduct['ZSQLCatalog'].manage_addSQLCatalog(id=container_path[-1], title='')
+ if len(container_container.objectIds()) == 1:
+ container_container.default_sql_catalog_id = container_path[-1]
+ container = portal.unrestrictedTraverse(container_path)
else:
raise
container_ids = container.objectIds()
@@ -759,6 +788,9 @@
if trash and trashbin is not None:
self.portal_trash.backupObject(trashbin, container_path, object_id, save=1, keep_subobjects=1)
container.manage_delObjects([object_id])
+ if container.aq_parent.meta_type == 'ERP5 Catalog' and len(container.objectIds()) == 0:
+ # We are removing a ZSQLMethod, remove the SQLCatalog if empty
+ container.aq_parent.manage_delObjects([container.id])
except (NotFound, KeyError, BadRequest):
# object is already backup and/or removed
pass
@@ -1628,10 +1660,7 @@
def build(self, context, **kw):
ObjectTemplateItem.build(self, context, **kw)
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate build', 0, 'catalog not found')
return
@@ -1657,10 +1686,7 @@
catalog.filter_dict[method_id]['type']
def export(self, context, bta, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate, export', 0, 'no SQL catalog was available')
return
@@ -1679,7 +1705,6 @@
XMLExportImport.exportXML(obj._p_jar, obj._p_oid, f)
bta.addObject(obj=f.getvalue(), name=id, path=path)
# add all datas specific to catalog inside one file
- catalog = context.portal_catalog.getSQLCatalog()
method_id = obj.id
object_path = os.path.join(path, method_id+'.catalog_keys.xml')
@@ -1724,10 +1749,7 @@
def install(self, context, trashbin, **kw):
ObjectTemplateItem.install(self, context, trashbin, **kw)
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -1828,10 +1850,7 @@
catalog.sql_clear_catalog = tuple(sql_clear_catalog)
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2671,10 +2690,7 @@
class CatalogResultKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2699,10 +2715,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2730,10 +2743,7 @@
catalog.sql_search_result_keys = sql_search_result_keys
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2771,10 +2781,7 @@
class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2799,10 +2806,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2833,10 +2837,7 @@
catalog.sql_catalog_related_keys = tuple(sql_catalog_related_keys)
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2874,10 +2875,7 @@
class CatalogResultTableTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2902,10 +2900,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2933,10 +2928,7 @@
catalog.sql_search_tables = tuple(sql_search_tables)
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -2975,10 +2967,7 @@
class CatalogKeywordKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3003,10 +2992,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3034,10 +3020,7 @@
catalog.sql_catalog_keyword_search_keys = sql_keyword_keys
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3076,10 +3059,7 @@
class CatalogFullTextKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3104,10 +3084,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3135,10 +3112,7 @@
catalog.sql_catalog_full_text_search_keys = sql_full_text_keys
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3178,10 +3152,7 @@
class CatalogRequestKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3206,10 +3177,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3237,10 +3205,7 @@
catalog.sql_catalog_request_keys = tuple(sql_catalog_request_keys)
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3279,10 +3244,7 @@
class CatalogMultivalueKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3307,10 +3269,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3337,10 +3296,7 @@
catalog.sql_catalog_multivalue_keys = tuple(sql_catalog_multivalue_keys)
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3379,10 +3335,7 @@
class CatalogTopicKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3407,10 +3360,7 @@
self._objects[file_name[:-4]] = list
def install(self, context, trashbin, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3438,10 +3388,7 @@
catalog.sql_catalog_topic_search_keys = sql_catalog_topic_search_keys
def uninstall(self, context, **kw):
- try:
- catalog = context.portal_catalog.getSQLCatalog()
- except KeyError:
- catalog = None
+ catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
@@ -3984,6 +3931,8 @@
and the one installed if exists
"""
+ self.checkDependencies()
+
modified_object_list = {}
bt_title = self.getTitle()
@@ -4068,6 +4017,9 @@
# Check the format of business template, if old, force install
if self.getTemplateFormatVersion() == 0:
force = 1
+
+ if not force:
+ self.checkDependencies()
site = self.getPortalObject()
from Products.ERP5.ERP5Site import ERP5Generator
@@ -4121,7 +4073,7 @@
update_catalog = 1
break
if update_catalog:
- catalog = local_configuration.portal_catalog.getSQLCatalog()
+ catalog = _getCatalogValue(self)
if (catalog is None) or (not site.isIndexable):
LOG('Business Template', 0, 'no SQL Catalog available')
update_catalog = 0
More information about the Erp5-report
mailing list