Commit e4d79e1b authored by Romain Courteaud's avatar Romain Courteaud

Try to reduce the lenght of the code by making it a little more generic.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3760 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6444947a
...@@ -198,13 +198,8 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -198,13 +198,8 @@ class PathTemplateItem(ObjectTemplateItem):
class CategoryTemplateItem(ObjectTemplateItem): class CategoryTemplateItem(ObjectTemplateItem):
def __init__(self, id_list, **kw): def __init__(self, id_list, tool_id='portal_categories', **kw):
ObjectTemplateItem.__init__(self, id_list, **kw) ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
tool_id = 'portal_categories'
id_list = self._archive.keys()
self._archive.clear()
for id in id_list:
self._archive["%s/%s" % (tool_id, id)] = None
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
...@@ -249,8 +244,8 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -249,8 +244,8 @@ class CategoryTemplateItem(ObjectTemplateItem):
class SkinTemplateItem(ObjectTemplateItem): class SkinTemplateItem(ObjectTemplateItem):
def __init__(self, id_list, **kw): def __init__(self, id_list, tool_id='portal_skins', **kw):
ObjectTemplateItem.__init__(self, id_list, tool_id='portal_skins', **kw) ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
...@@ -353,9 +348,8 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -353,9 +348,8 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
default_chain=', '.join(pw._default_chain) default_chain=', '.join(pw._default_chain)
return (default_chain, new_dict) return (default_chain, new_dict)
def __init__(self, id_list, **kw): def __init__(self, id_list, tool_id='portal_types', **kw):
kw['tool_id'] = 'portal_types' ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
ObjectTemplateItem.__init__(self, id_list, **kw)
self._workflow_chain_archive = PersistentMapping() self._workflow_chain_archive = PersistentMapping()
def build(self, context, **kw): def build(self, context, **kw):
...@@ -396,8 +390,8 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -396,8 +390,8 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
class CatalogMethodTemplateItem(ObjectTemplateItem): class CatalogMethodTemplateItem(ObjectTemplateItem):
def __init__(self, id_list, **kw): def __init__(self, id_list, tool_id='portal_catalog', **kw):
ObjectTemplateItem.__init__(self, id_list, tool_id='portal_catalog', **kw) ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
self._is_catalog_method_archive = PersistentMapping() self._is_catalog_method_archive = PersistentMapping()
self._is_catalog_list_method_archive = PersistentMapping() self._is_catalog_list_method_archive = PersistentMapping()
self._is_uncatalog_method_archive = PersistentMapping() self._is_uncatalog_method_archive = PersistentMapping()
...@@ -581,6 +575,7 @@ class ActionTemplateItem(BaseTemplateItem): ...@@ -581,6 +575,7 @@ class ActionTemplateItem(BaseTemplateItem):
return path, None, None return path, None, None
def __init__(self, id_list, **kw): def __init__(self, id_list, **kw):
# XXX It's look like ObjectTemplateItem __init__
BaseTemplateItem.__init__(self, id_list, **kw) BaseTemplateItem.__init__(self, id_list, **kw)
id_list = self._archive.keys() id_list = self._archive.keys()
self._archive.clear() self._archive.clear()
...@@ -638,9 +633,6 @@ class ActionTemplateItem(BaseTemplateItem): ...@@ -638,9 +633,6 @@ class ActionTemplateItem(BaseTemplateItem):
class SitePropertyTemplateItem(BaseTemplateItem): class SitePropertyTemplateItem(BaseTemplateItem):
def __init__(self, id_list, **kw):
BaseTemplateItem.__init__(self, id_list, **kw)
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
...@@ -676,9 +668,6 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -676,9 +668,6 @@ class SitePropertyTemplateItem(BaseTemplateItem):
class ModuleTemplateItem(BaseTemplateItem): class ModuleTemplateItem(BaseTemplateItem):
def __init__(self, id_list, **kw):
BaseTemplateItem.__init__(self, id_list, **kw)
def build(self, context, **kw): def build(self, context, **kw):
BaseTemplateItem.build(self, context, **kw) BaseTemplateItem.build(self, context, **kw)
p = context.getPortalObject() p = context.getPortalObject()
...@@ -1055,9 +1044,12 @@ class BusinessTemplate(XMLObject): ...@@ -1055,9 +1044,12 @@ class BusinessTemplate(XMLObject):
- go to "BT" menu. Refresh list. Select BT. Click register. - go to "BT" menu. Refresh list. Select BT. Click register.
- go to "BT" menu. Select register BT. Define params. Click install / update. - go to "BT" menu. Select register BT. Define params.
Click install / update.
- go to "BT" menu. Create new BT. Define BT elements (workflow, methods, attributes, etc.). Click publish. Provide URL. - go to "BT" menu. Create new BT.
Define BT elements (workflow, methods, attributes, etc.).
Click publish. Provide URL.
Done. Done.
""" """
...@@ -1082,93 +1074,35 @@ class BusinessTemplate(XMLObject): ...@@ -1082,93 +1074,35 @@ class BusinessTemplate(XMLObject):
, PropertySheet.BusinessTemplate , PropertySheet.BusinessTemplate
) )
# Factory Type Information # This is a global variable
factory_type_information = \ # Order is important for installation
{ 'id' : portal_type _item_name_list = [
, 'meta_type' : meta_type '_product_item',
, 'description' : """\ '_property_sheet_item',
Business Template is a set of definitions, such as skins, portal types and categories. This is used to set up a new ERP5 site very efficiently.""" '_document_item',
, 'icon' : 'order_line_icon.gif' '_extension_item',
, 'product' : 'ERP5Type' '_test_item',
, 'factory' : 'addBusinessTemplate' '_role_item',
, 'immediate_view' : 'BusinessTemplate_view' '_message_translation_item',
, 'allow_discussion' : 1 '_workflow_item',
, 'allowed_content_types': ( '_catalog_method_item',
) '_site_property_item',
, 'filter_content_types' : 1 '_portal_type_item',
, 'global_allow' : 1 '_category_item',
, 'actions' : '_module_item',
( { 'id' : 'view' '_path_item',
, 'name' : 'View' '_skin_item',
, 'category' : 'object_view' '_action_item',
, 'action' : 'BusinessTemplate_view' '_catalog_result_key_item',
, 'permissions' : ( '_catalog_related_key_item',
Permissions.View, ) '_catalog_result_table_item',
} ]
, { 'id' : 'history'
, 'name' : 'History' def __init__(self, *args, **kw):
, 'category' : 'object_view' XMLObject.__init__(self, *args, **kw)
, 'action' : 'Base_viewHistory' # Initialize all item to None
, 'permissions' : ( for item_name in self._item_name_list:
Permissions.View, ) setattr(self, item_name, None)
}
, { 'id' : 'metadata'
, 'name' : 'Metadata'
, 'category' : 'object_view'
, 'action' : 'Base_viewMetadata'
, 'permissions' : (
Permissions.ManageProperties, )
}
, { 'id' : 'translate'
, 'name' : 'Translate'
, 'category' : 'object_exchange'
, 'action' : 'translation_template_view'
, 'permissions' : (
Permissions.TranslateContent, )
}
, { 'id' : 'update'
, 'name' : 'Update Business Template'
, 'category' : 'object_action'
, 'action' : 'BusinessTemplate_update'
, 'permissions' : (
Permissions.ModifyPortalContent, )
}
, { 'id' : 'save'
, 'name' : 'Save Business Template'
, 'category' : 'object_action'
, 'action' : 'BusinessTemplate_save'
, 'permissions' : (
Permissions.ManagePortal, )
}
, { 'id' : 'export'
, 'name' : 'Export Business Template'
, 'category' : 'object_action'
, 'action' : 'BusinessTemplate_export'
, 'permissions' : (
Permissions.ManagePortal, )
}
)
}
_workflow_item = None
_skin_item = None
_category_item = None
_catalog_method_item = None
_path_item = None
_portal_type_item = None
_action_item = None
_site_property_item = None
_module_item = None
_document_item = None
_property_sheet_item = None
_extension_item = None
_test_item = None
_product_item = None
_role_item = None
_catalog_result_key_item = None
_catalog_related_key_item = None
_catalog_result_table_item = None
_message_translation_item = None
def manage_afterAdd(self, item, container): def manage_afterAdd(self, item, container):
""" """
...@@ -1177,9 +1111,12 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1177,9 +1111,12 @@ Business Template is a set of definitions, such as skins, portal types and categ
portal_workflow = getToolByName(self, 'portal_workflow') portal_workflow = getToolByName(self, 'portal_workflow')
if portal_workflow is not None: if portal_workflow is not None:
# Make sure that the installation state is "not installed". # Make sure that the installation state is "not installed".
if portal_workflow.getStatusOf('business_template_installation_workflow', self) is not None: if portal_workflow.getStatusOf(
# XXX Not good to access the attribute directly, but there is no API for clearing the history. 'business_template_installation_workflow', self) is not None:
self.workflow_history['business_template_installation_workflow'] = None # XXX Not good to access the attribute directly,
# but there is no API for clearing the history.
self.workflow_history[
'business_template_installation_workflow'] = None
def build(self): def build(self):
""" """
...@@ -1187,7 +1124,6 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1187,7 +1124,6 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
# Make sure that everything is sane. # Make sure that everything is sane.
self.clean() self.clean()
# XXX Trim down the history to prevent it from bloating the bt5 file. # XXX Trim down the history to prevent it from bloating the bt5 file.
# XXX Is there any better way to shrink the size??? # XXX Is there any better way to shrink the size???
portal_workflow = getToolByName(self, 'portal_workflow') portal_workflow = getToolByName(self, 'portal_workflow')
...@@ -1199,82 +1135,52 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1199,82 +1135,52 @@ Business Template is a set of definitions, such as skins, portal types and categ
original_history_dict[wf_id] = history original_history_dict[wf_id] = history
LOG('Business Template', 0, 'trim down the history of %s' % (wf_id,)) LOG('Business Template', 0, 'trim down the history of %s' % (wf_id,))
self.workflow_history[wf_id] = history[-30:] self.workflow_history[wf_id] = history[-30:]
# Store all datas
# Copy portal_types self._portal_type_item = \
self._portal_type_item = PortalTypeTemplateItem(self.getTemplatePortalTypeIdList()) PortalTypeTemplateItem(self.getTemplatePortalTypeIdList())
self._portal_type_item.build(self) self._workflow_item = \
WorkflowTemplateItem(self.getTemplateWorkflowIdList())
# Copy workflows self._skin_item = \
self._workflow_item = WorkflowTemplateItem(self.getTemplateWorkflowIdList()) SkinTemplateItem(self.getTemplateSkinIdList())
self._workflow_item.build(self) self._category_item = \
CategoryTemplateItem(self.getTemplateBaseCategoryList())
# Copy skins self._catalog_method_item = \
self._skin_item = SkinTemplateItem(self.getTemplateSkinIdList()) CatalogMethodTemplateItem(self.getTemplateCatalogMethodIdList())
self._skin_item.build(self) self._action_item = \
ActionTemplateItem(self.getTemplateActionPathList())
# Copy categories self._site_property_item = \
self._category_item = CategoryTemplateItem(self.getTemplateBaseCategoryList()) SitePropertyTemplateItem(self.getTemplateSitePropertyIdList())
self._category_item.build(self) self._module_item = \
ModuleTemplateItem(self.getTemplateModuleIdList())
# Copy catalog methods self._document_item = \
self._catalog_method_item = CatalogMethodTemplateItem(self.getTemplateCatalogMethodIdList()) DocumentTemplateItem(self.getTemplateDocumentIdList())
self._catalog_method_item.build(self) self._property_sheet_item = \
PropertySheetTemplateItem(self.getTemplatePropertySheetIdList())
# Copy actions self._extension_item = \
self._action_item = ActionTemplateItem(self.getTemplateActionPathList()) ExtensionTemplateItem(self.getTemplateExtensionIdList())
self._action_item.build(self) self._test_item = \
TestTemplateItem(self.getTemplateTestIdList())
# Copy properties self._product_item = \
self._site_property_item = SitePropertyTemplateItem(self.getTemplateSitePropertyIdList()) ProductTemplateItem(self.getTemplateProductIdList())
self._site_property_item.build(self) self._role_item = \
RoleTemplateItem(self.getTemplateRoleList())
# Copy modules self._catalog_result_key_item = \
self._module_item = ModuleTemplateItem(self.getTemplateModuleIdList()) CatalogResultKeyTemplateItem(
self._module_item.build(self) self.getTemplateCatalogResultKeyList())
self._catalog_related_key_item = \
# Copy Document Classes CatalogRelatedKeyTemplateItem(
self._document_item = DocumentTemplateItem(self.getTemplateDocumentIdList()) self.getTemplateCatalogRelatedKeyList())
self._document_item.build(self) self._catalog_result_table_item = \
CatalogResultTableTemplateItem(
# Copy Propertysheet Classes self.getTemplateCatalogResultTableList())
self._property_sheet_item = PropertySheetTemplateItem(self.getTemplatePropertySheetIdList()) self._message_translation_item = \
self._property_sheet_item.build(self) MessageTranslationTemplateItem(
self.getTemplateMessageTranslationList())
# Copy Extensions Classes (useful for catalog) self._path_item = \
self._extension_item = ExtensionTemplateItem(self.getTemplateExtensionIdList()) PathTemplateItem(self.getTemplatePathList())
self._extension_item.build(self) # Build each part
for item_name in self._item_name_list:
# Copy Test Classes getattr(self, item_name).build(self)
self._test_item = TestTemplateItem(self.getTemplateTestIdList())
self._test_item.build(self)
# Copy Products
self._product_item = ProductTemplateItem(self.getTemplateProductIdList())
self._product_item.build(self)
# Copy roles
self._role_item = RoleTemplateItem(self.getTemplateRoleList())
self._role_item.build(self)
# Copy catalog result keys
self._catalog_result_key_item = CatalogResultKeyTemplateItem(self.getTemplateCatalogResultKeyList())
self._catalog_result_key_item.build(self)
# Copy catalog related keys
self._catalog_related_key_item = CatalogRelatedKeyTemplateItem(self.getTemplateCatalogRelatedKeyList())
self._catalog_related_key_item.build(self)
# Copy catalog result tables
self._catalog_result_table_item = CatalogResultTableTemplateItem(self.getTemplateCatalogResultTableList())
self._catalog_result_table_item.build(self)
# Copy message translations
self._message_translation_item = MessageTranslationTemplateItem(self.getTemplateMessageTranslationList())
self._message_translation_item.build(self)
# Other objects
self._path_item = PathTemplateItem(self.getTemplatePathList())
self._path_item.build(self)
build = WorkflowMethod(build) build = WorkflowMethod(build)
...@@ -1282,11 +1188,12 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1282,11 +1188,12 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
Publish in a format or another Publish in a format or another
""" """
return self.portal_templates.publish(self, url, username=username, password=password) return self.portal_templates.publish(self, url, username=username,
password=password)
def update(self): def update(self):
""" """
Update template: download new template defition Update template: download new template definition
""" """
return self.portal_templates.update(self) return self.portal_templates.update(self)
...@@ -1294,54 +1201,22 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1294,54 +1201,22 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
For install based on paramaters provided in **kw For install based on paramaters provided in **kw
""" """
installed_bt = self.portal_templates.getInstalledBusinessTemplate(self.getTitle()) installed_bt = self.portal_templates.getInstalledBusinessTemplate(
LOG('Business Template install', 0, 'self = %r, installed_bt = %r' % (self, installed_bt)) self.getTitle())
LOG('Business Template install', 0,
'self = %r, installed_bt = %r' % (self, installed_bt))
if installed_bt is not None: if installed_bt is not None:
installed_bt.trash(self) installed_bt.trash(self)
installed_bt.replace(self) installed_bt.replace(self)
# Update local dictionary containing all setup parameters # Update local dictionary containing all setup parameters
# This may include mappings # This may include mappings
self.portal_templates.updateLocalConfiguration(self, **kw) self.portal_templates.updateLocalConfiguration(self, **kw)
local_configuration = self.portal_templates.getLocalConfiguration(self) local_configuration = self.portal_templates.getLocalConfiguration(self)
# Install everything
# Classes and security information for item_name in self._item_name_list:
if self._product_item is not None: self._product_item.install(local_configuration) item = getattr(self, item_name)
if self._property_sheet_item is not None: self._property_sheet_item.install(local_configuration) if item is not None:
if self._document_item is not None: self._document_item.install(local_configuration) item.install(local_configuration)
if self._extension_item is not None: self._extension_item.install(local_configuration)
if self._test_item is not None: self._test_item.install(local_configuration)
if self._role_item is not None: self._role_item.install(local_configuration)
# Message translations
if self._message_translation_item is not None: self._message_translation_item.install(local_configuration)
# Objects and properties
if self._workflow_item is not None: self._workflow_item.install(local_configuration)
if self._catalog_method_item is not None: self._catalog_method_item.install(local_configuration)
if self._site_property_item is not None: self._site_property_item.install(local_configuration)
# Portal Types
if self._portal_type_item is not None: self._portal_type_item.install(local_configuration)
# Categories
if self._category_item is not None: self._category_item.install(local_configuration,**kw)
# Modules.
if self._module_item is not None: self._module_item.install(local_configuration)
# Install Paths after Modules, as we may want to keep static objects in some modules defined in the BT.
if self._path_item is not None: self._path_item.install(local_configuration)
# Skins
if self._skin_item is not None: self._skin_item.install(local_configuration)
# Actions, catalog
if self._action_item is not None: self._action_item.install(local_configuration)
if self._catalog_result_key_item is not None: self._catalog_result_key_item.install(local_configuration)
if self._catalog_related_key_item is not None: self._catalog_related_key_item.install(local_configuration)
if self._catalog_result_table_item is not None: self._catalog_result_table_item.install(local_configuration)
# It is better to clear cache because the installation of a template # It is better to clear cache because the installation of a template
# adds many new things into the portal. # adds many new things into the portal.
clearCache() clearCache()
...@@ -1351,47 +1226,22 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1351,47 +1226,22 @@ Business Template is a set of definitions, such as skins, portal types and categ
def trash(self, new_bt, **kw): def trash(self, new_bt, **kw):
""" """
Trash unnecessary items before upograding to a new business template. Trash unnecessary items before upgrading to a new business
This is similar to uninstall, but different in that this does not remove template.
all items. This is similar to uninstall, but different in that this does
not remove all items.
""" """
# Update local dictionary containing all setup parameters # Update local dictionary containing all setup parameters
# This may include mappings # This may include mappings
self.portal_templates.updateLocalConfiguration(self, **kw) self.portal_templates.updateLocalConfiguration(self, **kw)
local_configuration = self.portal_templates.getLocalConfiguration(self) local_configuration = self.portal_templates.getLocalConfiguration(self)
# Trash everything
# Actions, catalog for item_name in self._item_name_list[::-1]:
if self._action_item is not None: self._action_item.trash(local_configuration, new_bt._action_item) item = getattr(self, item_name)
if self._catalog_result_key_item is not None: self._catalog_result_key_item.trash(local_configuration, new_bt._catalog_result_key_item) if item is not None:
if self._catalog_related_key_item is not None: self._catalog_related_key_item.trash(local_configuration, new_bt._catalog_related_key_item) item.trash(
if self._catalog_result_table_item is not None: self._catalog_result_table_item.trash(local_configuration, new_bt._catalog_result_table_item) local_configuration,
getattr(new_bt, item_name))
# Skins
if self._skin_item is not None: self._skin_item.trash(local_configuration, new_bt._skin_item)
# Portal Types
if self._portal_type_item is not None: self._portal_type_item.trash(local_configuration, new_bt._portal_type_item)
# Modules.
if self._module_item is not None: self._module_item.trash(local_configuration, new_bt._module_item)
# Objects and properties
if self._path_item is not None: self._path_item.trash(local_configuration, new_bt._path_item)
if self._workflow_item is not None: self._workflow_item.trash(local_configuration, new_bt._workflow_item)
if self._category_item is not None: self._category_item.trash(local_configuration, new_bt._category_item)
if self._catalog_method_item is not None: self._catalog_method_item.trash(local_configuration, new_bt._catalog_method_item)
if self._site_property_item is not None: self._site_property_item.trash(local_configuration, new_bt._site_property_item)
# Message translations
if self._message_translation_item is not None: self._message_translation_item.trash(local_configuration, new_bt._message_translation_item)
# Classes and security information
if self._product_item is not None: self._product_item.trash(local_configuration, new_bt._product_item)
if self._property_sheet_item is not None: self._property_sheet_item.trash(local_configuration, new_bt._property_sheet_item)
if self._document_item is not None: self._document_item.trash(local_configuration, new_bt._document_item)
if self._extension_item is not None: self._extension_item.trash(local_configuration, new_bt._extension_item)
if self._test_item is not None: self._test_item.trash(local_configuration, new_bt._test_item)
if self._role_item is not None: self._role_item.trash(local_configuration, new_bt._role_item)
def uninstall(self, **kw): def uninstall(self, **kw):
""" """
...@@ -1401,42 +1251,14 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1401,42 +1251,14 @@ Business Template is a set of definitions, such as skins, portal types and categ
# This may include mappings # This may include mappings
self.portal_templates.updateLocalConfiguration(self, **kw) self.portal_templates.updateLocalConfiguration(self, **kw)
local_configuration = self.portal_templates.getLocalConfiguration(self) local_configuration = self.portal_templates.getLocalConfiguration(self)
# Uninstall everything
# Actions, catalog # Trash everything
if self._action_item is not None: self._action_item.uninstall(local_configuration) for item_name in self._item_name_list[::-1]:
if self._catalog_result_key_item is not None: self._catalog_result_key_item.uninstall(local_configuration) item = getattr(self, item_name)
if self._catalog_related_key_item is not None: self._catalog_related_key_item.uninstall(local_configuration) if item is not None:
if self._catalog_result_table_item is not None: self._catalog_result_table_item.uninstall(local_configuration) item.uninstall(local_configuration)
# It is better to clear cache because the uninstallation of a
# Skins # template deletes many things from the portal.
if self._skin_item is not None: self._skin_item.uninstall(local_configuration)
# Portal Types
if self._portal_type_item is not None: self._portal_type_item.uninstall(local_configuration)
# Modules.
if self._module_item is not None: self._module_item.uninstall(local_configuration)
# Objects and properties
if self._path_item is not None: self._path_item.uninstall(local_configuration)
if self._workflow_item is not None: self._workflow_item.uninstall(local_configuration)
if self._category_item is not None: self._category_item.uninstall(local_configuration)
if self._catalog_method_item is not None: self._catalog_method_item.uninstall(local_configuration)
if self._site_property_item is not None: self._site_property_item.uninstall(local_configuration)
# Message translations
if self._message_translation_item is not None: self._message_translation_item.uninstall(local_configuration)
# Classes and security information
if self._product_item is not None: self._product_item.uninstall(local_configuration)
if self._property_sheet_item is not None: self._property_sheet_item.uninstall(local_configuration)
if self._document_item is not None: self._document_item.uninstall(local_configuration)
if self._extension_item is not None: self._extension_item.uninstall(local_configuration)
if self._test_item is not None: self._test_item.uninstall(local_configuration)
if self._role_item is not None: self._role_item.uninstall(local_configuration)
# It is better to clear cache because the uninstallation of a template
# deletes many things from the portal.
clearCache() clearCache()
uninstall = WorkflowMethod(uninstall) uninstall = WorkflowMethod(uninstall)
...@@ -1446,49 +1268,43 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1446,49 +1268,43 @@ Business Template is a set of definitions, such as skins, portal types and categ
Clean built information. Clean built information.
""" """
# First, remove obsolete attributes if present. # First, remove obsolete attributes if present.
for attr in ('_action_archive', '_document_archive', '_extension_archive', '_test_archive', '_module_archive', for attr in ( '_action_archive',
'_object_archive', '_portal_type_archive', '_property_archive', '_property_sheet_archive'): '_document_archive',
'_extension_archive',
'_test_archive',
'_module_archive',
'_object_archive',
'_portal_type_archive',
'_property_archive',
'_property_sheet_archive'):
if hasattr(self, attr): if hasattr(self, attr):
delattr(self, attr) delattr(self, attr)
# Secondly, make attributes empty. # Secondly, make attributes empty.
self._workflow_item = None for item_name in self._item_name_list:
self._skin_item = None item = setattr(self, item_name, None)
self._category_item = None
self._catalog_method_item = None
self._path_item = None
self._portal_type_item = None
self._action_item = None
self._site_property_item = None
self._module_item = None
self._document_item = None
self._property_sheet_item = None
self._extension_item = None
self._test_item = None
self._product_item = None
self._role_item = None
self._catalog_result_key_item = None
self._catalog_related_key_item = None
self._catalog_result_table_item = None
self._message_translation_item = None
clean = WorkflowMethod(clean) clean = WorkflowMethod(clean)
security.declareProtected(Permissions.AccessContentsInformation, 'getBuildingState') security.declareProtected(Permissions.AccessContentsInformation,
'getBuildingState')
def getBuildingState(self, id_only=1): def getBuildingState(self, id_only=1):
""" """
Returns the current state in building Returns the current state in building
""" """
portal_workflow = getToolByName(self, 'portal_workflow') portal_workflow = getToolByName(self, 'portal_workflow')
wf = portal_workflow.getWorkflowById('business_template_building_workflow') wf = portal_workflow.getWorkflowById(
'business_template_building_workflow')
return wf._getWorkflowStateOf(self, id_only=id_only ) return wf._getWorkflowStateOf(self, id_only=id_only )
security.declareProtected(Permissions.AccessContentsInformation, 'getInstallationState') security.declareProtected(Permissions.AccessContentsInformation,
'getInstallationState')
def getInstallationState(self, id_only=1): def getInstallationState(self, id_only=1):
""" """
Returns the current state in installation Returns the current state in installation
""" """
portal_workflow = getToolByName(self, 'portal_workflow') portal_workflow = getToolByName(self, 'portal_workflow')
wf = portal_workflow.getWorkflowById('business_template_installation_workflow') wf = portal_workflow.getWorkflowById(
'business_template_installation_workflow')
return wf._getWorkflowStateOf(self, id_only=id_only ) return wf._getWorkflowStateOf(self, id_only=id_only )
security.declareProtected(Permissions.AccessContentsInformation, 'toxml') security.declareProtected(Permissions.AccessContentsInformation, 'toxml')
...@@ -1497,7 +1313,10 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1497,7 +1313,10 @@ Business Template is a set of definitions, such as skins, portal types and categ
Return this Business Template in XML Return this Business Template in XML
""" """
portal_templates = getToolByName(self, 'portal_templates') portal_templates = getToolByName(self, 'portal_templates')
export_string = portal_templates.manage_exportObject(id=self.getId(), toxml=1, download=1) export_string = portal_templates.manage_exportObject(
id=self.getId(),
toxml=1,
download=1)
return export_string return export_string
def _getOrderedList(self, id): def _getOrderedList(self, id):
...@@ -1506,7 +1325,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1506,7 +1325,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
ordered list ordered list
""" """
#LOG('BuisinessTemplate _getOrderedList', 0, 'id = %s' % repr(id)) #LOG('BuisinessTemplate _getOrderedList', 0, 'id = %s' % repr(id))
result = getattr(self,id,()) result = getattr(self, id, ())
if result is None: result = () if result is None: result = ()
if result != (): if result != ():
result = list(result) result = list(result)
...@@ -1569,3 +1388,15 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -1569,3 +1388,15 @@ Business Template is a set of definitions, such as skins, portal types and categ
ordered list ordered list
""" """
return self._getOrderedList('template_message_translation') return self._getOrderedList('template_message_translation')
def diff(self):
"""
Return a 'diff' of the business template compared to the
__btsave__ version.
"""
# Diff everything
# for item_name in self._item_name_list[::-1]:
# item = getattr(self, item_name)
# if item is not None:
# item.uninstall(local_configuration)
pass
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