Commit 40d35a36 authored by Nicolas Dumazet's avatar Nicolas Dumazet

adapt DocumentationHelper & introspection code

The property holder is now the portal type class itself.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43154 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a7b7c799
...@@ -331,9 +331,9 @@ class PropertyHolder(object): ...@@ -331,9 +331,9 @@ class PropertyHolder(object):
Invokes appropriate factory and create an accessor Invokes appropriate factory and create an accessor
""" """
fake_accessor = getattr(self, id) fake_accessor = getattr(self, id)
ptype = getattr(self, '_portal_type', None) ptype = getattr(self, 'portal_type', None)
if ptype is None: if ptype is None:
ptype = self.portal_type ptype = self._portal_type
if fake_accessor is PropertyHolder.WORKFLOW_METHOD_MARKER: if fake_accessor is PropertyHolder.WORKFLOW_METHOD_MARKER:
# Case 1 : a workflow method only # Case 1 : a workflow method only
accessor = Base._doNothing accessor = Base._doNothing
...@@ -437,7 +437,7 @@ class PropertyHolder(object): ...@@ -437,7 +437,7 @@ class PropertyHolder(object):
if y is PropertyHolder.WORKFLOW_METHOD_MARKER or x == '__ac_permissions__': if y is PropertyHolder.WORKFLOW_METHOD_MARKER or x == '__ac_permissions__':
continue continue
if len(y) == 0: if len(y) == 0:
raise ValueError("problem at %s %s" % (self._portal_type, x)) continue
if not issubclass(y[0], Accessor): if not issubclass(y[0], Accessor):
continue continue
elif not isinstance(y, Accessor): elif not isinstance(y, Accessor):
...@@ -1595,7 +1595,12 @@ class Base( CopyContainer, ...@@ -1595,7 +1595,12 @@ class Base( CopyContainer,
Content properties are filtered out in getPropertyIdList so Content properties are filtered out in getPropertyIdList so
that rendering in ZMI is compatible with Zope standard properties that rendering in ZMI is compatible with Zope standard properties
""" """
return [property['id'] for property in self._erp5_properties if property['type'] == 'content'] result = set()
for parent_class in self.__class__.mro():
for property in getattr(parent_class, '_properties', []):
if property['type'] == 'content':
result.add(property['id'])
return list(result)
security.declareProtected( Permissions.View, 'getStandardPropertyIdList' ) security.declareProtected( Permissions.View, 'getStandardPropertyIdList' )
def getStandardPropertyIdList(self): def getStandardPropertyIdList(self):
...@@ -1603,7 +1608,12 @@ class Base( CopyContainer, ...@@ -1603,7 +1608,12 @@ class Base( CopyContainer,
Return standard properties of the current instance. Return standard properties of the current instance.
Unlike getPropertyIdList, properties are not converted or rewritten here. Unlike getPropertyIdList, properties are not converted or rewritten here.
""" """
return [property['id'] for property in self._erp5_properties if property['type'] != 'content'] result = set()
for parent_class in self.__class__.mro():
for property in getattr(parent_class, '_properties', []):
if property['type'] != 'content':
result.add(property['id'])
return list(result)
# Catalog Related # Catalog Related
security.declareProtected( Permissions.View, 'getObject' ) security.declareProtected( Permissions.View, 'getObject' )
......
...@@ -73,6 +73,7 @@ class TempObjectLibrary(object): ...@@ -73,6 +73,7 @@ class TempObjectLibrary(object):
temp_object = container.newContent(portal_type=portal_type, temp_object = container.newContent(portal_type=portal_type,
id=portal_type, id=portal_type,
temp_object=1) temp_object=1)
self.portal_type_dict[portal_type] = temp_object self.portal_type_dict[portal_type] = temp_object
return temp_object return temp_object
...@@ -297,12 +298,7 @@ class DocumentationHelper(Implicit): ...@@ -297,12 +298,7 @@ class DocumentationHelper(Implicit):
return self.view() return self.view()
def _getPropertyHolder(self): def _getPropertyHolder(self):
property_holder = None return self.getDocumentedObject().__class__
key = self.getPortalType(), self.getDocumentedObject().__class__
if not(Base.aq_portal_type.has_key(key)):
self.getDocumentedObject().initializePortalTypeDynamicProperties()
property_holder = Base.aq_portal_type[key]
return property_holder
InitializeClass(DocumentationHelper) InitializeClass(DocumentationHelper)
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Base import Base
from DocumentationHelper import DocumentationHelper, TempObjectLibrary from DocumentationHelper import DocumentationHelper, TempObjectLibrary
from DocumentationSection import DocumentationSection from DocumentationSection import DocumentationSection
from PortalTypeInstanceDocumentationHelper import PortalTypeInstanceDocumentationHelper from PortalTypeInstanceDocumentationHelper import PortalTypeInstanceDocumentationHelper
...@@ -270,9 +269,8 @@ class PortalTypeDocumentationHelper(DocumentationHelper): ...@@ -270,9 +269,8 @@ class PortalTypeDocumentationHelper(DocumentationHelper):
def _getPropertyHolder(self): def _getPropertyHolder(self):
portal_type = getPortalType(self.uri) portal_type = getPortalType(self.uri)
temp_object = self.getTempInstance(portal_type) import erp5.portal_type
dir_temp = dir(temp_object) return getattr(erp5.portal_type, portal_type)
return Base.aq_portal_type[(portal_type, temp_object.__class__)]
security.declareProtected(Permissions.AccessContentsInformation, 'getWorkflowMethodIdList') security.declareProtected(Permissions.AccessContentsInformation, 'getWorkflowMethodIdList')
def getWorkflowMethodIdList(self): def getWorkflowMethodIdList(self):
...@@ -300,8 +298,10 @@ class PortalTypeDocumentationHelper(DocumentationHelper): ...@@ -300,8 +298,10 @@ class PortalTypeDocumentationHelper(DocumentationHelper):
Return a list of tuple (id, method) for every class method Return a list of tuple (id, method) for every class method
""" """
portal_type = getPortalType(self.uri) portal_type = getPortalType(self.uri)
klass = self.getTempInstance(portal_type).__class__.__bases__[0] import erp5.portal_type
return self._getPropertyHolder().getClassMethodIdList(klass, **kw) klass = getattr(erp5.portal_type, portal_type)
document_class = klass.__bases__[0]
return klass.getClassMethodIdList(document_class, **kw)
security.declareProtected(Permissions.AccessContentsInformation, 'getClassMethodUriList') security.declareProtected(Permissions.AccessContentsInformation, 'getClassMethodUriList')
def getClassMethodUriList(self, inherited=0, **kw): def getClassMethodUriList(self, inherited=0, **kw):
...@@ -310,7 +310,8 @@ class PortalTypeDocumentationHelper(DocumentationHelper): ...@@ -310,7 +310,8 @@ class PortalTypeDocumentationHelper(DocumentationHelper):
""" """
method_id_list = self.getClassMethodIdList(inherited=inherited, **kw) method_id_list = self.getClassMethodIdList(inherited=inherited, **kw)
portal_type = getPortalType(self.uri) portal_type = getPortalType(self.uri)
klass = self.getTempInstance(portal_type).__class__.__bases__[0] import erp5.portal_type
klass = getattr(erp5.portal_type, portal_type)
class_name = klass.__name__ class_name = klass.__name__
module = klass.__module__ module = klass.__module__
uri_prefix = '%s.%s.' % (module, class_name) uri_prefix = '%s.%s.' % (module, class_name)
......
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