Commit f42c34e9 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Bind constraints list to portal type class. This fixes

testDynamicClassGeneration.TestZodbPropertySheet.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43041 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c5352be8
...@@ -305,11 +305,10 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -305,11 +305,10 @@ 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, )
attribute_dict = {} attribute_dict = dict(_categories=[], constraints=[])
interface_list = [] interface_list = []
base_category_list = []
else: else:
base_tuple, interface_list, base_category_list, attribute_dict = class_definition base_tuple, interface_list, attribute_dict = class_definition
klass.__isghost__ = False klass.__isghost__ = False
klass.__bases__ = base_tuple klass.__bases__ = base_tuple
...@@ -319,8 +318,6 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -319,8 +318,6 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
for key, value in attribute_dict.iteritems(): for key, value in attribute_dict.iteritems():
setattr(klass, key, value) setattr(klass, key, value)
klass._categories = base_category_list
for interface in interface_list: for interface in interface_list:
classImplements(klass, interface) classImplements(klass, interface)
......
...@@ -144,14 +144,16 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -144,14 +144,16 @@ 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__
- interface_list: list of zope interfaces the portal type implements - interface_list: list of zope interfaces the portal type implements
- base_category_list: base categories defined on the portal_type itself
(a.k.a. excluding categories from Property sheets and documents)
- attribute dictionary: any additional attributes to put on the class - attribute dictionary: any additional attributes to put on the class
""" """
# LOG("ERP5Type.dynamic", INFO, "Loading portal type " + portal_type_name) # LOG("ERP5Type.dynamic", INFO, "Loading portal type " + portal_type_name)
global core_portal_type_class_dict global core_portal_type_class_dict
attribute_dict = dict(portal_type=portal_type_name,
_categories=[],
constraints=[])
if portal_type_name in core_portal_type_class_dict: if portal_type_name in core_portal_type_class_dict:
if not core_portal_type_class_dict[portal_type_name]['generating']: if not core_portal_type_class_dict[portal_type_name]['generating']:
# Loading the (full) outer portal type class # Loading the (full) outer portal type class
...@@ -167,14 +169,13 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -167,14 +169,13 @@ 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,), [], [], {}) 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.
portal_type = getattr(site.portal_types, portal_type_name, None) portal_type = getattr(site.portal_types, portal_type_name, None)
type_class = None type_class = None
base_category_list = []
if portal_type is not None: if portal_type is not None:
# type_class has a compatibility getter that should return # type_class has a compatibility getter that should return
...@@ -191,7 +192,7 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -191,7 +192,7 @@ 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()
base_category_list = portal_type.getTypeBaseCategoryList() attribute_dict['_categories'] = portal_type.getTypeBaseCategoryList()
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..."
...@@ -317,10 +318,12 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -317,10 +318,12 @@ def generatePortalTypeClass(site, portal_type_name):
erp5.accessor_holder) erp5.accessor_holder)
accessor_holder_list.insert(0, accessor_holder) accessor_holder_list.insert(0, accessor_holder)
base_category_set = set(base_category_list) base_category_set = set(attribute_dict['_categories'])
for accessor_holder in accessor_holder_list: for accessor_holder in accessor_holder_list:
base_category_set.update(accessor_holder._categories) base_category_set.update(accessor_holder._categories)
base_category_list = list(base_category_set) attribute_dict['constraints'].extend(accessor_holder.constraints)
attribute_dict['_categories'] = list(base_category_set)
property_sheet_generating_portal_type_set.remove(portal_type_name) property_sheet_generating_portal_type_set.remove(portal_type_name)
...@@ -350,8 +353,7 @@ def generatePortalTypeClass(site, portal_type_name): ...@@ -350,8 +353,7 @@ def generatePortalTypeClass(site, portal_type_name):
return (tuple(base_class_list), return (tuple(base_class_list),
interface_class_list, interface_class_list,
base_category_list, attribute_dict)
dict(portal_type=portal_type_name))
from lazy_class import generateLazyPortalTypeClass from lazy_class import generateLazyPortalTypeClass
def initializeDynamicModules(): def initializeDynamicModules():
......
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