Commit 90acac69 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Do not generate twice category accessors from property sheets.

* cls._categories contains all categories associated to an object.
  This is list is aggregated and contains all categories associated
  by a property sheet, and all categories coming from the portal
  type definition itself.
* Categories defined on property sheets get their accessors generated
  and assigned on accessor holders.
* But categories defined on the portal type need to be generated
  distincly, on the portal type class itself. When doing so, we must
  generate accessors only for portal type categories, and ignore
  those already generated.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43362 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4fd3cf21
...@@ -208,10 +208,10 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -208,10 +208,10 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
raise AttributeError raise AttributeError
def generatePortalTypeAccessors(cls, site): def generatePortalTypeAccessors(cls, site, portal_type_category_list):
createAllCategoryAccessors(site, createAllCategoryAccessors(site,
cls, cls,
cls._categories, portal_type_category_list,
createExpressionContext(site, site)) createExpressionContext(site, site))
# make sure that category accessors from the portal type definition # make sure that category accessors from the portal type definition
# are generated, no matter what # are generated, no matter what
...@@ -305,10 +305,12 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -305,10 +305,12 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
"Could not access Portal Type Object for type %r" "Could not access Portal Type Object for type %r"
% portal_type, error=sys.exc_info()) % portal_type, error=sys.exc_info())
base_tuple = (ERP5BaseBroken, ) base_tuple = (ERP5BaseBroken, )
portal_type_category_list = []
attribute_dict = dict(_categories=[], constraints=[]) attribute_dict = dict(_categories=[], constraints=[])
interface_list = [] interface_list = []
else: else:
base_tuple, interface_list, attribute_dict = class_definition base_tuple, portal_type_category_list, \
interface_list, attribute_dict = class_definition
klass.__isghost__ = False klass.__isghost__ = False
klass.__bases__ = base_tuple klass.__bases__ = base_tuple
...@@ -325,7 +327,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -325,7 +327,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
# because they dont have accessors, and will mess up # because they dont have accessors, and will mess up
# workflow methods. We KNOW that we will re-load this type anyway # workflow methods. We KNOW that we will re-load this type anyway
if len(base_tuple) > 1: if len(base_tuple) > 1:
klass.generatePortalTypeAccessors(site) klass.generatePortalTypeAccessors(site, portal_type_category_list)
# need to set %s__roles__ for generated methods # need to set %s__roles__ for generated methods
cls.setupSecurity() cls.setupSecurity()
......
...@@ -163,6 +163,8 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -163,6 +163,8 @@ def generatePortalTypeClass(site, portal_type_name):
Returns tuple with 4 items: Returns tuple with 4 items:
- base_tuple: a tuple of classes to be used as __bases__ - base_tuple: a tuple of classes to be used as __bases__
- base_category_list: categories defined on the portal type
(and portal type only: this excludes property sheets)
- interface_list: list of zope interfaces the portal type implements - interface_list: list of zope interfaces the portal type implements
- attribute dictionary: any additional attributes to put on the class - attribute dictionary: any additional attributes to put on the class
""" """
...@@ -170,6 +172,7 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -170,6 +172,7 @@ def generatePortalTypeClass(site, portal_type_name):
global core_portal_type_class_dict global core_portal_type_class_dict
portal_type_category_list = []
attribute_dict = dict(portal_type=portal_type_name, attribute_dict = dict(portal_type=portal_type_name,
_categories=[], _categories=[],
constraints=[]) constraints=[])
...@@ -189,7 +192,7 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -189,7 +192,7 @@ def generatePortalTypeClass(site, portal_type_name):
# Don't do anything else, just allow to load fully the outer # Don't do anything else, just allow to load fully the outer
# portal type class # portal type class
return ((klass,), [], attribute_dict) return ((klass,), [], [], attribute_dict)
# Do not use __getitem__ (or _getOb) because portal_type may exist in a # Do not use __getitem__ (or _getOb) because portal_type may exist in a
# type provider other than Types Tool. # type provider other than Types Tool.
...@@ -212,7 +215,8 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -212,7 +215,8 @@ def generatePortalTypeClass(site, portal_type_name):
mixin_list = portal_type.getTypeMixinList() mixin_list = portal_type.getTypeMixinList()
interface_list = portal_type.getTypeInterfaceList() interface_list = portal_type.getTypeInterfaceList()
attribute_dict['_categories'] = portal_type.getTypeBaseCategoryList() portal_type_category_list = portal_type.getTypeBaseCategoryList()
attribute_dict['_categories'] = portal_type_category_list[:]
else: else:
LOG("ERP5Type.dynamic", WARNING, LOG("ERP5Type.dynamic", WARNING,
"Cannot find a portal type definition for '%s', trying to guess..." "Cannot find a portal type definition for '%s', trying to guess..."
...@@ -346,6 +350,7 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -346,6 +350,7 @@ def generatePortalTypeClass(site, portal_type_name):
# % (portal_type_name, repr(baseclasses))) # % (portal_type_name, repr(baseclasses)))
return (tuple(base_class_list), return (tuple(base_class_list),
portal_type_category_list,
interface_class_list, interface_class_list,
attribute_dict) attribute_dict)
......
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