Commit 398469d0 authored by Romain Courteaud's avatar Romain Courteaud

Add variation property API.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3945 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0680fa89
......@@ -232,6 +232,52 @@ class Amount(Base, Variated):
result = self.portal_categories.getBaseCategoryList()
return result
#####################################################################
# Variation property API
#####################################################################
security.declareProtected(Permissions.AccessContentsInformation,
'getVariationPropertyDict')
def getVariationPropertyDict(self):
"""
Return a dictionary of:
{property_id: property_value,}
Each property is a variation of the resource.
The variation property list is defined on resource,
with setVariationPropertyList.
"""
property_dict = {}
resource = self.getDefaultResourceValue()
if resource is not None:
variation_list = resource.getVariationPropertyList()
for variation_property in variation_list:
# XXX Accessor not used
property_dict[variation_property] = \
getattr(self, variation_property, None)
return property_dict
security.declareProtected(Permissions.ModifyPortalContent,
'setVariationPropertyDict')
def setVariationPropertyDict(self, property_dict):
"""
Take a parameter a property dict like:
{property_id: property_value,}
Each property is a variation of the resource.
If one of the property_id is not a variation, a exception
KeyError is raised.
"""
resource = self.getDefaultResourceValue()
if resource is not None:
variation_list = resource.getVariationPropertyList()
else:
variation_list = []
for property_id, property_value in property_dict.items():
if property_id not in variation_list:
raise KeyError, "Can not set the property variation '%s'" % \
property_id
else:
# XXX Accessor not used
setattr(self, property_id, property_value)
security.declareProtected(Permissions.AccessContentsInformation,
'getQuantityUnitRangeItemList')
def getQuantityUnitRangeItemList(self, base_category_list=()):
......
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