Commit ba862d77 authored by Sebastien Robin's avatar Sebastien Robin

Commit work done by Baye:

- Add Helper at site level
- make it more robust


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21119 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ccbfa826
...@@ -162,7 +162,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -162,7 +162,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
def getPortalTypeIdList(self): def getPortalTypeIdList(self):
""" """
""" """
return self.getDocumentedObject().template_portal_type_id return getattr(self.getDocumentedObject(), 'template_portal_type_id', [])
security.declareProtected( Permissions.AccessContentsInformation, 'getPortalTypeURIList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getPortalTypeURIList' )
def getPortalTypeURIList(self): def getPortalTypeURIList(self):
...@@ -176,7 +176,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -176,7 +176,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
def getSkinFolderIdList(self): def getSkinFolderIdList(self):
""" """
""" """
return self.getDocumentedObject().template_skin_id return getattr(self.getDocumentedObject(), 'template_skin_id', [])
security.declareProtected( Permissions.AccessContentsInformation, 'getSkinFolderURIList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getSkinFolderURIList' )
def getSkinFolderURIList(self): def getSkinFolderURIList(self):
...@@ -191,7 +191,8 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -191,7 +191,8 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
""" """
""" """
dc_workflow_list = [] dc_workflow_list = []
for wf in self.getDocumentedObject().template_workflow_id: #for wf in self.getDocumentedObject().template_workflow_id:
for wf in getattr(self.getDocumentedObject(), 'template_workflow_id', []):
url = '/' + self.getPortalObject().id + '/portal_workflow/' + wf url = '/' + self.getPortalObject().id + '/portal_workflow/' + wf
wf_object = self.getPortalObject().unrestrictedTraverse(url) wf_object = self.getPortalObject().unrestrictedTraverse(url)
if wf_object.__class__.__name__ == 'DCWorkflowDefinition': if wf_object.__class__.__name__ == 'DCWorkflowDefinition':
...@@ -211,7 +212,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -211,7 +212,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
""" """
""" """
workflow_list = [] workflow_list = []
for wf in self.getDocumentedObject().template_workflow_id: for wf in getattr(self.getDocumentedObject(), 'template_workflow_id', []):
url = '/' + self.getPortalObject().id + '/portal_workflow/' + wf url = '/' + self.getPortalObject().id + '/portal_workflow/' + wf
wf_object = self.getPortalObject().unrestrictedTraverse(url) wf_object = self.getPortalObject().unrestrictedTraverse(url)
if wf_object.__class__.__name__ == 'InteractionWorkflowDefinition': if wf_object.__class__.__name__ == 'InteractionWorkflowDefinition':
...@@ -230,7 +231,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -230,7 +231,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
def getBaseCategoryList(self): def getBaseCategoryList(self):
""" """
""" """
return self.getDocumentedObject().template_base_category return getattr(self.getDocumentedObject(), 'template_base_category', [])
security.declareProtected( Permissions.AccessContentsInformation, 'getPortalTypeURIList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getPortalTypeURIList' )
def getBaseCategoryURIList(self): def getBaseCategoryURIList(self):
...@@ -244,7 +245,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -244,7 +245,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
def getModuleIdList(self): def getModuleIdList(self):
""" """
""" """
return self.getDocumentedObject().template_module_id return getattr(self.getDocumentedObject(), 'template_module_id', [])
security.declareProtected( Permissions.AccessContentsInformation, 'getModuleURIList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getModuleURIList' )
def getModuleURIList(self): def getModuleURIList(self):
...@@ -258,7 +259,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper): ...@@ -258,7 +259,7 @@ class BusinessTemplateDocumentationHelper(DocumentationHelper):
def getCatalogMethodIdList(self): def getCatalogMethodIdList(self):
""" """
""" """
return self.getDocumentedObject().template_catalog_method_id return getattr(self.getDocumentedObject(), 'template_catalog_method_id', [])
security.declareProtected( Permissions.AccessContentsInformation, 'getCatalogMethodURIList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCatalogMethodURIList' )
def getCatalogMethodURIList(self): def getCatalogMethodURIList(self):
......
...@@ -68,10 +68,10 @@ class CatalogMethodDocumentationHelper(DocumentationHelper): ...@@ -68,10 +68,10 @@ class CatalogMethodDocumentationHelper(DocumentationHelper):
""" """
Returns the source code of the documentation helper Returns the source code of the documentation helper
""" """
from zLOG import LOG, INFO
source_code = self.getDocumentedObject().src source_code = self.getDocumentedObject().src
if hasattr(self.erp5, 'portal_transforms'): portal_transforms = getattr(self, 'portal_transforms', None)
portal_transforms = self.erp5.portal_transforms if portal_transforms is None:
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of text to html') 'Transformation Tool is not installed. No convertion of text to html')
return source_code return source_code
......
...@@ -90,14 +90,16 @@ class DCWorkflowDocumentationHelper(DocumentationHelper): ...@@ -90,14 +90,16 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
""" """
Returns the title of the documentation helper Returns the title of the documentation helper
""" """
return self.getInstance().__dict__["title"] return self.getInstance().title
security.declareProtected( Permissions.AccessContentsInformation, 'getDescription' ) security.declareProtected( Permissions.AccessContentsInformation, 'getDescription' )
def getDescription(self): def getDescription(self):
""" """
Returns the description of the documentation helper Returns the description of the documentation helper
""" """
return self.getInstance().__dict__["description"] #return self.getInstance().__dict__["description"]
return self.getInstance().description
security.declareProtected( Permissions.AccessContentsInformation, 'getSectionList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getSectionList' )
......
...@@ -84,13 +84,16 @@ class DCWorkflowScriptDocumentationHelper(DocumentationHelper): ...@@ -84,13 +84,16 @@ class DCWorkflowScriptDocumentationHelper(DocumentationHelper):
""" """
Returns the source code the workflow script Returns the source code the workflow script
""" """
from zLOG import LOG, INFO
source_code = "" source_code = ""
wf_script = self.getDocumentedObject() wf_script = self.getDocumentedObject()
if hasattr(wf_script, '__dict__'): source_code = wf_script.document_src()
if '_body' in wf_script.__dict__.keys(): portal_transforms = getattr(self, 'portal_transforms', None)
source_code = wf_script.__dict__['_body'] if portal_transforms is not None:
if hasattr(self.erp5, 'portal_transforms'): REQUEST = getattr(self, 'REQUEST', None)
portal_transforms = self.erp5.portal_transforms if REQUEST is not None:
if REQUEST.get('portal_skin', 'View' ) != 'View':
return source_code
else: else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html') 'Transformation Tool is not installed. No convertion of python script to html')
......
##############################################################################
#
# Copyright (c) 2007-2008 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Acquisition import Implicit
from AccessControl import ClassSecurityInfo
from Globals import InitializeClass
from DocumentationHelper import DocumentationHelper
from DocumentationSection import DocumentationSection
from Products.ERP5Type import Permissions
from zLOG import LOG, INFO
class ERP5SiteDocumentationHelper(DocumentationHelper):
"""
Provides access to all documentation information
of an ERP5 Site.
"""
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# API Implementation
security.declareProtected( Permissions.AccessContentsInformation, 'getTitle' )
def getTitle(self):
"""
Returns the title of the documentation helper
"""
return self.getDocumentedObject().title
security.declareProtected( Permissions.AccessContentsInformation, 'getType' )
def getType(self):
"""
Returns the type of the documentation helper
"""
return "ERP5 Site"
security.declareProtected( Permissions.AccessContentsInformation, 'getSectionList' )
def getSectionList(self):
"""
Returns a list of documentation sections
"""
return map(lambda x: x.__of__(self), [
DocumentationSection(
id='business_template',
title='Business Template',
class_name='BusinessTemplateDocumentationHelper',
uri_list=self.getBusinessTemplateUriList(),
),
])
# Specific methods
security.declareProtected( Permissions.AccessContentsInformation, 'getDescription' )
def getDescription(self):
"""
Returns the description of the documentation helper
"""
return self.getDocumentedObject().description
security.declareProtected( Permissions.AccessContentsInformation, 'getBusinessTemplateIdList' )
def getBusinessTemplateIdList(self):
"""
"""
bt_list = []
for bt in self.getDocumentedObject().portal_templates.objectValues():
current_state = ''
for wh in bt.workflow_history['business_template_installation_workflow']:
current_state = wh['installation_state']
if current_state == 'installed':
bt_list.append(bt.getId())
return bt_list
security.declareProtected( Permissions.AccessContentsInformation, 'getBusinessTemplateItemList' )
def getBusinessTemplateItemList(self):
"""
"""
bt_list = []
for bt in self.getDocumentedObject().portal_templates.objectValues():
revision = ""
version = ""
if hasattr(bt, 'revision'):
revision = bt.revision
if hasattr(bt, 'version'):
version = bt.version
current_state = ''
for wh in bt.workflow_history['business_template_installation_workflow']:
current_state = wh['installation_state']
if current_state == 'installed':
bt_list.append((bt.getId(), bt.title, bt.description, version, revision))
return bt_list
security.declareProtected( Permissions.AccessContentsInformation, 'getBusinessTemplateURIList' )
def getBusinessTemplateURIList(self):
"""
"""
bt_list = self.getBusinessTemplateItemList()
base_uri = '/'+self.uri.split('/')[1]
return map(lambda x: ('%s/portal_templates/%s' % (base_uri, x[0]),x[1], x[2], x[3], x[4]), bt_list)
security.declareProtected( Permissions.AccessContentsInformation, 'getBusinessTemplateUriList' )
def getBusinessTemplateUriList(self):
"""
"""
bt_list = self.getBusinessTemplateItemList()
base_uri = '/'+self.uri.split('/')[1]
return map(lambda x: ('%s/portal_templates/%s' % (base_uri, x[0])), bt_list)
InitializeClass(ERP5SiteDocumentationHelper)
...@@ -90,14 +90,14 @@ class InteractionWorkflowDocumentationHelper(DocumentationHelper): ...@@ -90,14 +90,14 @@ class InteractionWorkflowDocumentationHelper(DocumentationHelper):
""" """
Returns the title of the documentation helper Returns the title of the documentation helper
""" """
return self.getInstance().__dict__["title"] return self.getInstance().title
security.declareProtected( Permissions.AccessContentsInformation, 'getDescription' ) security.declareProtected( Permissions.AccessContentsInformation, 'getDescription' )
def getDescription(self): def getDescription(self):
""" """
Returns the description of the documentation helper Returns the description of the documentation helper
""" """
return self.getInstance().__dict__["description"] return self.getInstance().description
security.declareProtected( Permissions.AccessContentsInformation, 'getSectionList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getSectionList' )
......
...@@ -68,10 +68,10 @@ class PageTemplateDocumentationHelper(DocumentationHelper): ...@@ -68,10 +68,10 @@ class PageTemplateDocumentationHelper(DocumentationHelper):
""" """
Returns the source code the script python Returns the source code the script python
""" """
from zLOG import LOG, INFO
source_code = self.getDocumentedObject()._text source_code = self.getDocumentedObject()._text
if hasattr(self.erp5, 'portal_transforms'): portal_transforms = getattr(self, 'portal_transforms', None)
portal_transforms = self.erp5.portal_transforms if portal_transforms is None:
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html') 'Transformation Tool is not installed. No convertion of python script to html')
return source_code return source_code
......
...@@ -68,14 +68,14 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper): ...@@ -68,14 +68,14 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper):
""" """
Returns the source code the property sheet Returns the source code the property sheet
""" """
from zLOG import LOG, INFO
source_code = "" source_code = ""
property_sheet_file = self.getDocumentedObject() property_sheet_file = self.getDocumentedObject()
if property_sheet_file is not None: if property_sheet_file is not None:
property_sheet_file.seek(0) property_sheet_file.seek(0)
source_code = property_sheet_file.read() source_code = property_sheet_file.read()
if hasattr(self.erp5, 'portal_transforms'): portal_transforms = getattr(self, 'portal_transforms', None)
portal_transforms = self.erp5.portal_transforms if portal_transforms is not None:
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html') 'Transformation Tool is not installed. No convertion of python script to html')
return source_code return source_code
......
...@@ -68,10 +68,10 @@ class ScriptPythonDocumentationHelper(DocumentationHelper): ...@@ -68,10 +68,10 @@ class ScriptPythonDocumentationHelper(DocumentationHelper):
""" """
Returns the source code the script python Returns the source code the script python
""" """
from zLOG import LOG, INFO
source_code = self.getDocumentedObject()._body source_code = self.getDocumentedObject()._body
if hasattr(self.erp5, 'portal_transforms'): portal_transforms = getattr(self, 'portal_transforms', None)
portal_transforms = self.erp5.portal_transforms if portal_transforms is None:
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html') 'Transformation Tool is not installed. No convertion of python script to html')
return source_code return source_code
......
...@@ -68,10 +68,10 @@ class ZSQLMethodDocumentationHelper(DocumentationHelper): ...@@ -68,10 +68,10 @@ class ZSQLMethodDocumentationHelper(DocumentationHelper):
""" """
Returns the source code of the documentation helper Returns the source code of the documentation helper
""" """
from zLOG import LOG, INFO
source_code = self.getDocumentedObject().src source_code = self.getDocumentedObject().src
if hasattr(self.erp5, 'portal_transforms'): portal_transforms = getattr(self, 'portal_transforms', None)
portal_transforms = self.erp5.portal_transforms if portal_transforms is None:
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO, LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of text to html') 'Transformation Tool is not installed. No convertion of text to html')
return source_code return source_code
......
...@@ -60,4 +60,5 @@ from ScriptPythonDocumentationHelper import ScriptPythonDocumentationHelper ...@@ -60,4 +60,5 @@ from ScriptPythonDocumentationHelper import ScriptPythonDocumentationHelper
from ERP5FormDocumentationHelper import ERP5FormDocumentationHelper from ERP5FormDocumentationHelper import ERP5FormDocumentationHelper
from PageTemplateDocumentationHelper import PageTemplateDocumentationHelper from PageTemplateDocumentationHelper import PageTemplateDocumentationHelper
from ZSQLMethodDocumentationHelper import ZSQLMethodDocumentationHelper from ZSQLMethodDocumentationHelper import ZSQLMethodDocumentationHelper
from ERP5SiteDocumentationHelper import ERP5SiteDocumentationHelper
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