diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index ede126dd5fa986f018a4860ea644c8bfea995041..6158751fa5d3147ff484d79c88cca19960af20af 100644 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -827,14 +827,15 @@ class Base( CopyContainer, def _aq_key(self): return (self.portal_type, self.__class__) - def _propertyMap(self): + def _propertyMap(self, local_properties=False): """ Method overload - properties are now defined on the ptype """ klass = self.__class__ property_list = [] # Get all the accessor holders for this portal type - if hasattr(klass, 'getAccessorHolderPropertyList'): - property_list += \ - self.__class__.getAccessorHolderPropertyList() + if not local_properties: + if hasattr(klass, 'getAccessorHolderPropertyList'): + property_list += \ + self.__class__.getAccessorHolderPropertyList() property_list += getattr(self, '_local_properties', []) return tuple(property_list) @@ -1273,8 +1274,10 @@ class Base( CopyContainer, result = [result] return result if d is not _MARKER: - return ERP5PropertyManager.getProperty(self, key, d=d, **kw) - return ERP5PropertyManager.getProperty(self, key, **kw) + return ERP5PropertyManager.getProperty(self, key, d=d, + local_properties=True, **kw) + return ERP5PropertyManager.getProperty(self, key, + local_properties=True, **kw) security.declareProtected( Permissions.AccessContentsInformation, 'getPropertyList' ) def getPropertyList(self, key, d=None): @@ -1349,8 +1352,9 @@ class Base( CopyContainer, # If we are here, this means we do not use a property that # comes from an ERP5 PropertySheet, we should use the # PropertyManager - if ERP5PropertyManager.hasProperty(self,key): - ERP5PropertyManager._updateProperty(self, key, value) + if ERP5PropertyManager.hasProperty(self,key, local_properties=True): + ERP5PropertyManager._updateProperty(self, key, value, + local_properties=True) else: ERP5PropertyManager._setProperty(self, key, value, type=type) # This should not be there, because this ignore all checks made by diff --git a/product/ERP5Type/patches/PropertyManager.py b/product/ERP5Type/patches/PropertyManager.py index ff32b022149d0475258a76fe775b7a0b0f23d722..f7768f4fd35ac3e0d9c78660fc6fa7475f9016a8 100644 --- a/product/ERP5Type/patches/PropertyManager.py +++ b/product/ERP5Type/patches/PropertyManager.py @@ -34,7 +34,7 @@ PropertyManager_manage_propertiesForm=DTMLFile('properties', property_extensible_schema__=1) -def PropertyManager_updateProperty(self, id, value): +def PropertyManager_updateProperty(self, id, value, local_properties=False): # Update the value of an existing property. If value # is a string, an attempt will be made to convert # the value to the type of the existing property. @@ -43,22 +43,25 @@ def PropertyManager_updateProperty(self, id, value): if not self.hasProperty(id): raise BadRequest, 'The property %s does not exist' % escape(id) if isinstance(value, str): - proptype=self.getPropertyType(id) or 'string' + proptype=self.getPropertyType(id, local_properties=local_properties) \ + or 'string' if type_converters.has_key(proptype): value=type_converters[proptype](value) self._setPropValue(id, value) -def PropertyManager_hasProperty(self, id): +def PropertyManager_hasProperty(self, id, local_properties=False): """Return true if object has a property 'id'""" - for p in self.propertyIds(): + for p in self.propertyIds(local_properties=local_properties): if id==p: return 1 return 0 -def PropertyManager_getProperty(self, id, d=None, evaluate=1): +def PropertyManager_getProperty(self, id, d=None, evaluate=1, + local_properties=False): """Get the property 'id', returning the optional second argument or None if no such property is found.""" - property_type = self.getPropertyType(id) + property_type = self.getPropertyType(id, + local_properties=local_properties) if evaluate and property_type == 'tales': value = getattr(self, id) expression = Expression(value) @@ -68,10 +71,14 @@ def PropertyManager_getProperty(self, id, d=None, evaluate=1): return getattr(self, id) return d -def PropertyManager_getPropertyType(self, id): +def PropertyManager_getPropertyType(self, id, local_properties=False): """Get the type of property 'id', returning None if no such property exists""" - for md in self._propertyMap(): + if local_properties: + property_map = getattr(self, '_local_properties', []) + else: + property_map = self._propertyMap() + for md in property_map: if md['id']==id: return md.get('type', 'string') return None @@ -138,9 +145,10 @@ def PropertyManager_delProperty(self, id): self._local_properties=tuple(filter(lambda i, n=id: i['id'] != n, getattr(self, '_local_properties', ()))) -def PropertyManager_propertyIds(self): +def PropertyManager_propertyIds(self, local_properties=False): """Return a list of property ids """ - return map(lambda i: i['id'], self._propertyMap()) + return map(lambda i: i['id'], self._propertyMap( + local_properties=local_properties)) def PropertyManager_propertyValues(self): """Return a list of actual property objects """ @@ -150,7 +158,7 @@ def PropertyManager_propertyItems(self): """Return a list of (id,property) tuples """ return map(lambda i,s=self: (i['id'],s.getProperty(i['id'])), self._propertyMap()) -def PropertyManager_propertyMap(self): +def PropertyManager_propertyMap(self, local_properties=False): """Return a tuple of mappings, giving meta-data for properties """ property_map = list(self._properties) property_dict = {}