Commit 843c4d06 authored by Sebastien Robin's avatar Sebastien Robin

- Merged ScriptPythonDocumentationHelper and DCWorkflowScriptDocumentationHelper

- Merged CatalogMethodDocumentationHelper and ZSQLMethodDocumentationHelper
- Improve the rendering of parameters of python scripts


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24644 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4687ac43
...@@ -46,6 +46,11 @@ def getDefinitionString(obj=None): ...@@ -46,6 +46,11 @@ def getDefinitionString(obj=None):
fc.append('*args') fc.append('*args')
elif fc_var_names[i] == 'kw': elif fc_var_names[i] == 'kw':
fc.append('**kw') fc.append('**kw')
elif fc_var_names[i].startswith('_') or \
fc_var_names[i].startswith('Products'):
# In case of python scripts, we have many things
# that we do not want to display
break
else: else:
fc.append(fc_var_names[i]) fc.append(fc_var_names[i])
fd = obj.func_defaults fd = obj.func_defaults
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
from Acquisition import Implicit from Acquisition import Implicit
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass from Globals import InitializeClass
from DocumentationHelper import DocumentationHelper from ZSQLMethodDocumentationHelper import ZSQLMethodDocumentationHelper
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
class CatalogMethodDocumentationHelper(DocumentationHelper): class CatalogMethodDocumentationHelper(ZSQLMethodDocumentationHelper):
""" """
Provides documentation about a catalog method Provides documentation about a catalog method
""" """
...@@ -63,28 +63,6 @@ class CatalogMethodDocumentationHelper(DocumentationHelper): ...@@ -63,28 +63,6 @@ class CatalogMethodDocumentationHelper(DocumentationHelper):
""" """
return getattr(self.getDocumentedObject(), 'title', '') return getattr(self.getDocumentedObject(), 'title', '')
security.declareProtected(Permissions.AccessContentsInformation, 'getSource' )
def getSource(self):
"""
Returns the source code the catalog method
"""
from zLOG import LOG, INFO
source_code = getattr(self.getDocumentedObject(), 'src', '')
portal_transforms = getattr(self, 'portal_transforms', None)
if portal_transforms is not None:
REQUEST = getattr(self, 'REQUEST', None)
if REQUEST is not None:
if REQUEST.get('portal_skin', 'View' ) != 'View':
return source_code
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html')
return source_code
src_mimetype='text/plain'
mime_type = 'text/html'
source_html = portal_transforms.convertTo(mime_type, source_code, mimetype = src_mimetype)
return source_html.getData()
security.declareProtected(Permissions.AccessContentsInformation, 'getConnectionId' ) security.declareProtected(Permissions.AccessContentsInformation, 'getConnectionId' )
def getConnectionId(self): def getConnectionId(self):
""" """
......
...@@ -29,42 +29,16 @@ ...@@ -29,42 +29,16 @@
from Acquisition import Implicit from Acquisition import Implicit
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass from Globals import InitializeClass
from DocumentationHelper import DocumentationHelper from ScriptPythonDocumentationHelper import ScriptPythonDocumentationHelper
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from AccessorMethodDocumentationHelper import getDefinitionString
class DCWorkflowScriptDocumentationHelper(DocumentationHelper): class DCWorkflowScriptDocumentationHelper(ScriptPythonDocumentationHelper):
""" """
Provides documentation about a workflow script Provides documentation about a workflow script
""" """
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
def __init__(self, uri):
self.uri = uri
security.declareProtected(Permissions.AccessContentsInformation, 'getType' )
def getType(self):
"""
Returns the type of the documentation helper
"""
return "Workflow Script"
security.declareProtected(Permissions.AccessContentsInformation, 'getId' )
def getId(self):
"""
Returns the id of the documentation helper
"""
return getattr(self.getDocumentedObject(), "__name__", "")
security.declareProtected(Permissions.AccessContentsInformation, 'getTitle' )
def getTitle(self):
"""
Returns the title of the documentation helper
"""
return getattr(self.getDocumentedObject(), "title", "")
security.declareProtected(Permissions.AccessContentsInformation, 'getSectionList') security.declareProtected(Permissions.AccessContentsInformation, 'getSectionList')
def getSectionList(self): def getSectionList(self):
""" """
...@@ -72,39 +46,4 @@ class DCWorkflowScriptDocumentationHelper(DocumentationHelper): ...@@ -72,39 +46,4 @@ class DCWorkflowScriptDocumentationHelper(DocumentationHelper):
""" """
return [] return []
security.declareProtected( Permissions.AccessContentsInformation, 'getDefinition' )
def getDefinition(self):
"""
Returns the definition of the script with the name of the script and arguments
"""
return getDefinitionString(self.getDocumentedObject())
security.declareProtected( Permissions.AccessContentsInformation, 'getSourceCode' )
def getSourceCode(self):
"""
Returns the source code the workflow script
"""
from zLOG import LOG, INFO
source_code = ""
wf_script = self.getDocumentedObject()
source_code = wf_script.document_src()
portal_transforms = getattr(self, 'portal_transforms', None)
if portal_transforms is not None:
REQUEST = getattr(self, 'REQUEST', None)
if REQUEST is not None:
if REQUEST.get('portal_skin', 'View' ) != 'View':
doc_string = source_code.split('"""')
if len(doc_string)>1 and not doc_string[0]:
return doc_string[1]
else:
return ""
else:
LOG('DCWorkflowScriptDocumentationHelper', INFO,
'Transformation Tool is not installed. No convertion of python script to html')
return source_code
src_mimetype='text/x-python'
mime_type = 'text/html'
source_html = portal_transforms.convertTo(mime_type, source_code, mimetype = src_mimetype)
return source_html.getData()
InitializeClass(DCWorkflowScriptDocumentationHelper) InitializeClass(DCWorkflowScriptDocumentationHelper)
...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo
from Globals import InitializeClass from Globals import InitializeClass
from DocumentationHelper import DocumentationHelper from DocumentationHelper import DocumentationHelper
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from AccessorMethodDocumentationHelper import getDefinitionString
class ScriptPythonDocumentationHelper(DocumentationHelper): class ScriptPythonDocumentationHelper(DocumentationHelper):
""" """
...@@ -89,4 +90,11 @@ class ScriptPythonDocumentationHelper(DocumentationHelper): ...@@ -89,4 +90,11 @@ class ScriptPythonDocumentationHelper(DocumentationHelper):
source_html = portal_transforms.convertTo(mime_type, source_code, mimetype = src_mimetype) source_html = portal_transforms.convertTo(mime_type, source_code, mimetype = src_mimetype)
return source_html.getData() return source_html.getData()
security.declareProtected( Permissions.AccessContentsInformation, 'getDefinition' )
def getDefinition(self):
"""
Returns the definition of the script with the name of the script and arguments
"""
return getDefinitionString(self.getDocumentedObject())
InitializeClass(ScriptPythonDocumentationHelper) InitializeClass(ScriptPythonDocumentationHelper)
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