From 90acac69d3f3ba0596c1c678bc2dbafc6a426890 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Wed, 16 Feb 2011 04:09:55 +0000 Subject: [PATCH] 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 --- product/ERP5Type/dynamic/lazy_class.py | 10 ++++++---- product/ERP5Type/dynamic/portal_type_class.py | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/product/ERP5Type/dynamic/lazy_class.py b/product/ERP5Type/dynamic/lazy_class.py index e0410b2c7c..a1efdf9a14 100644 --- a/product/ERP5Type/dynamic/lazy_class.py +++ b/product/ERP5Type/dynamic/lazy_class.py @@ -208,10 +208,10 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): raise AttributeError - def generatePortalTypeAccessors(cls, site): + def generatePortalTypeAccessors(cls, site, portal_type_category_list): createAllCategoryAccessors(site, cls, - cls._categories, + portal_type_category_list, createExpressionContext(site, site)) # make sure that category accessors from the portal type definition # are generated, no matter what @@ -305,10 +305,12 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): "Could not access Portal Type Object for type %r" % portal_type, error=sys.exc_info()) base_tuple = (ERP5BaseBroken, ) + portal_type_category_list = [] attribute_dict = dict(_categories=[], constraints=[]) interface_list = [] 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.__bases__ = base_tuple @@ -325,7 +327,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): # because they dont have accessors, and will mess up # workflow methods. We KNOW that we will re-load this type anyway if len(base_tuple) > 1: - klass.generatePortalTypeAccessors(site) + klass.generatePortalTypeAccessors(site, portal_type_category_list) # need to set %s__roles__ for generated methods cls.setupSecurity() diff --git a/product/ERP5Type/dynamic/portal_type_class.py b/product/ERP5Type/dynamic/portal_type_class.py index a5bff30baf..313ebeeb9a 100644 --- a/product/ERP5Type/dynamic/portal_type_class.py +++ b/product/ERP5Type/dynamic/portal_type_class.py @@ -163,6 +163,8 @@ def generatePortalTypeClass(site, portal_type_name): Returns tuple with 4 items: - 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 - attribute dictionary: any additional attributes to put on the class """ @@ -170,6 +172,7 @@ def generatePortalTypeClass(site, portal_type_name): global core_portal_type_class_dict + portal_type_category_list = [] attribute_dict = dict(portal_type=portal_type_name, _categories=[], constraints=[]) @@ -189,7 +192,7 @@ def generatePortalTypeClass(site, portal_type_name): # Don't do anything else, just allow to load fully the outer # portal type class - return ((klass,), [], attribute_dict) + return ((klass,), [], [], attribute_dict) # Do not use __getitem__ (or _getOb) because portal_type may exist in a # type provider other than Types Tool. @@ -212,7 +215,8 @@ def generatePortalTypeClass(site, portal_type_name): mixin_list = portal_type.getTypeMixinList() 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: LOG("ERP5Type.dynamic", WARNING, "Cannot find a portal type definition for '%s', trying to guess..." @@ -346,6 +350,7 @@ def generatePortalTypeClass(site, portal_type_name): # % (portal_type_name, repr(baseclasses))) return (tuple(base_class_list), + portal_type_category_list, interface_class_list, attribute_dict) -- 2.30.9