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')
......
...@@ -58,8 +58,8 @@ class DocumentationHelper(Implicit): ...@@ -58,8 +58,8 @@ class DocumentationHelper(Implicit):
def getDocumentedObject(self): def getDocumentedObject(self):
if self.uri.startswith('portal_classes/temp_instance'): if self.uri.startswith('portal_classes/temp_instance'):
url, method = self.uri.split('#') url, method = self.uri.split('#')
portal_type = url.split('/')[-1] portal_type = url.split('/')[-1]
temp_folder = self.getPortalObject().portal_classes.newContent(id='temp_instance', portal_type='Folder', temp_object=1) temp_folder = self.getPortalObject().portal_classes.newContent(id='temp_instance', portal_type='Folder', temp_object=1)
temp_object = temp_folder.newContent(id=portal_type, portal_type=portal_type, temp_object=1) temp_object = temp_folder.newContent(id=portal_type, portal_type=portal_type, temp_object=1)
if '/' not in method: if '/' not in method:
...@@ -76,11 +76,11 @@ class DocumentationHelper(Implicit): ...@@ -76,11 +76,11 @@ class DocumentationHelper(Implicit):
zope_property_sheet = instance_home + '/PropertySheet' zope_property_sheet = instance_home + '/PropertySheet'
list_propertysheets = [zope_property_sheet,] list_propertysheets = [zope_property_sheet,]
for path in list_path: for path in list_path:
full_path = instance_home+'/Products/'+path full_path = instance_home+'/Products/'+path
if os.path.isdir(full_path) and os.path.exists(full_path+'/PropertySheet'): if os.path.isdir(full_path) and os.path.exists(full_path+'/PropertySheet'):
list_propertysheets.append(full_path+'/PropertySheet') list_propertysheets.append(full_path+'/PropertySheet')
for propertysheet_directory in list_propertysheets: for propertysheet_directory in list_propertysheets:
if os.path.exists(propertysheet_directory+'/'+file_name): if os.path.exists(propertysheet_directory+'/'+file_name):
file_url = propertysheet_directory+'/'+file_name file_url = propertysheet_directory+'/'+file_name
documented_object = open(file_url) documented_object = open(file_url)
elif '/' in self.uri and '#' not in self.uri: elif '/' in self.uri and '#' not in self.uri:
...@@ -89,20 +89,20 @@ class DocumentationHelper(Implicit): ...@@ -89,20 +89,20 @@ class DocumentationHelper(Implicit):
try: try:
documented_object = self.getPortalObject().portal_categories.resolveCategory(self.uri) documented_object = self.getPortalObject().portal_categories.resolveCategory(self.uri)
except: except:
documented_object = None documented_object = None
if documented_object is None: if documented_object is None:
documented_object = self.getPortalObject().unrestrictedTraverse(self.uri) documented_object = self.getPortalObject().unrestrictedTraverse(self.uri)
elif '/' in self.uri and '#' in self.uri: elif '/' in self.uri and '#' in self.uri:
if '?' in self.uri: if '?' in self.uri:
base_url, url = self.uri.split('?') base_url, url = self.uri.split('?')
type, name = url.split('#') type, name = url.split('#')
parent_object = self.getPortalObject().unrestrictedTraverse(base_url) parent_object = self.getPortalObject().unrestrictedTraverse(base_url)
object_list = getattr(parent_object, type, None) object_list = getattr(parent_object, type, None)
documented_object = None documented_object = None
if object_list is not None: if object_list is not None:
for obj in object_list: for obj in object_list:
if obj.__name__ == name: if obj.__name__ == name:
documented_object = obj documented_object = obj
else: else:
url, method = self.uri.split('#') url, method = self.uri.split('#')
documented_object = self.getPortalObject().unrestrictedTraverse(url) documented_object = self.getPortalObject().unrestrictedTraverse(url)
......
##############################################################################
#
# 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