Commit db5e05dc authored by Julien Muchembled's avatar Julien Muchembled

property_recordable: create '_recorded_property_dict' only if required

parent 1162ce93
...@@ -61,21 +61,22 @@ class PropertyRecordableMixin: ...@@ -61,21 +61,22 @@ class PropertyRecordableMixin:
id -- ID of the property id -- ID of the property
""" """
try: for property_info in self.getPropertyMap():
property_info = [x for x in self.getPropertyMap() \ if property_info['id'] == id:
if x['id'] == id][0] if property_info['type'] in list_types:
except IndexError:
if id in self.getBaseCategoryList():
value = self.getPropertyList(id) value = self.getPropertyList(id)
else: # should be local property else:
value = self.getProperty(id) value = self.getProperty(id)
break
else: else:
if property_info['type'] in list_types: if id in self.getBaseCategoryList():
value = self.getPropertyList(id) value = self.getPropertyList(id)
else: else: # should be local property
value = self.getProperty(id) value = self.getProperty(id)
recorded_property_dict = self._getRecordedPropertyDict() try:
recorded_property_dict[id] = value self._getRecordedPropertyDict()[id] = value
except AttributeError:
self._recorded_property_dict = PersistentMapping({id: value})
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'clearRecordedProperty') 'clearRecordedProperty')
...@@ -84,11 +85,7 @@ class PropertyRecordableMixin: ...@@ -84,11 +85,7 @@ class PropertyRecordableMixin:
Clears a previously recorded property from Clears a previously recorded property from
the property record. the property record.
""" """
recorded_property_dict = self._getRecordedPropertyDict() self._getRecordedPropertyDict({}).pop(id, None)
try:
del(recorded_property_dict[id])
except KeyError:
pass
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getRecordedPropertyIdList') 'getRecordedPropertyIdList')
...@@ -97,7 +94,7 @@ class PropertyRecordableMixin: ...@@ -97,7 +94,7 @@ class PropertyRecordableMixin:
Returns the list of property IDs which have Returns the list of property IDs which have
been recorded. been recorded.
""" """
return (self._getRecordedPropertyDict().keys()) return self._getRecordedPropertyDict({}).keys()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'isPropertyRecorded') 'isPropertyRecorded')
...@@ -108,7 +105,7 @@ class PropertyRecordableMixin: ...@@ -108,7 +105,7 @@ class PropertyRecordableMixin:
id -- ID of the property id -- ID of the property
""" """
return self._getRecordedPropertyDict().has_key(id) return id in self._getRecordedPropertyDict(())
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getRecordedProperty') 'getRecordedProperty')
...@@ -128,10 +125,9 @@ class PropertyRecordableMixin: ...@@ -128,10 +125,9 @@ class PropertyRecordableMixin:
which recorded properties in its context. which recorded properties in its context.
""" """
context = self.asContext() context = self.asContext()
context.edit(**dict(self._getRecordedPropertyDict())) # BBB: cast to dict is required for Python < 2.6
context.edit(**dict(self._getRecordedPropertyDict(())))
return context return context
def _getRecordedPropertyDict(self): def _getRecordedPropertyDict(self, *args):
if getattr(aq_base(self), '_recorded_property_dict', None) is None: return getattr(aq_base(self), '_recorded_property_dict', *args)
self._recorded_property_dict = PersistentMapping()
return self._recorded_property_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