From 78b72a4c38d852f69169911c7272030b751dd784 Mon Sep 17 00:00:00 2001 From: Romain Courteaud <romain@nexedi.com> Date: Tue, 10 Jan 2006 12:53:05 +0000 Subject: [PATCH] Add getVariationRangeCategoryList and getVariationRangeCategoryItemList to Variated. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5070 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/Resource.py | 76 +++++++++++++------------------ product/ERP5/Variated.py | 39 ++++++++++++++++ 2 files changed, 71 insertions(+), 44 deletions(-) diff --git a/product/ERP5/Document/Resource.py b/product/ERP5/Document/Resource.py index a8bed48f13..6ffaf99a40 100755 --- a/product/ERP5/Document/Resource.py +++ b/product/ERP5/Document/Resource.py @@ -87,6 +87,28 @@ class Resource(XMLMatrix, CoreResource, Variated): resource.getVariationRangeCategoryItemList => [(display, value)] + + ## Variation API (exemple) ## + Base categories defined: + - colour + - morphology + - size + Categories defined: + - colour/blue + - colour/red + - size/Man + - size/Woman + Resource 'resource' created with variation_base_category_list: + (colour, morphology, size) + + resource.getVariationRangeCategoryList + variation | individual variation | result + ____________________________________________________________________________________ + | | (colour/blue, colour/red, size/Man, size/Woman) + size/Man | | (colour/blue, colour/red, size/Man, size/Woman) + colour/blue | | (colour/blue, colour/red, size/Man, size/Woman) + | colour/1 | (colour/1, size/Man, size/Woman) + | morphology/2 | (colour/blue, colour/red, size/Man, size/Woman, morphology/2) """ result = [] if base_category_list is (): @@ -120,52 +142,14 @@ class Resource(XMLMatrix, CoreResource, Variated): other_base_category_dict.items()) other_base_category_list = map(lambda x: x[0], other_base_category_item_list) - for c in other_base_category_list: - result += self.portal_categories.unrestrictedTraverse(c).\ - getCategoryChildLogicalPathItemList( - base=base, - display_base_category=display_base_category, - display_none_category=0) - + # Get category variation + if len(other_base_category_list) != 0: + result += Variated.getVariationRangeCategoryItemList( + self, base_category_list=other_base_category_list, + base=base, display_base_category=display_base_category) + # Return result return result - security.declareProtected(Permissions.AccessContentsInformation, - 'getVariationRangeCategoryList') - def getVariationRangeCategoryList(self, base_category_list=(), base=1, - root=1, current_category=None): - """ - Returns the range of acceptable categories - - ## Variation API (exemple) ## - Base categories defined: - - colour - - morphology - - size - Categories defined: - - colour/blue - - colour/red - - size/Man - - size/Woman - Resource 'resource' created with variation_base_category_list: - (colour, morphology, size) - - resource.getVariationRangeCategoryList - variation | individual variation | result - ____________________________________________________________________________________ - | | (colour/blue, colour/red, size/Man, size/Woman) - size/Man | | (colour/blue, colour/red, size/Man, size/Woman) - colour/blue | | (colour/blue, colour/red, size/Man, size/Woman) - | colour/1 | (colour/1, size/Man, size/Woman) - | morphology/2 | (colour/blue, colour/red, size/Man, size/Woman, morphology/2) - """ - vrcil = self.getVariationRangeCategoryItemList( - base_category_list=base_category_list, - base=base, root=root, - current_category=current_category) - # display is on left - return map(lambda x: x[1], vrcil) - - security.declareProtected(Permissions.AccessContentsInformation, 'getVariationCategoryItemList') def getVariationCategoryItemList(self, base_category_list=(), @@ -418,6 +402,10 @@ class Resource(XMLMatrix, CoreResource, Variated): kw['resource'] = self.getRelativeUrl() return self.portal_simulation.getInventoryHistoryChart(**kw) + # XXX FIXME + # Method getCurrentMovementHistoryList, + # getAvailableMovementHistoryList, getFutureMovementHistoryList + # can be added security.declareProtected(Permissions.AccessContentsInformation, 'getMovementHistoryList') def getMovementHistoryList(self, **kw): diff --git a/product/ERP5/Variated.py b/product/ERP5/Variated.py index 6b55089c1b..67d9d4adf5 100755 --- a/product/ERP5/Variated.py +++ b/product/ERP5/Variated.py @@ -260,6 +260,45 @@ class Variated(Base): result += [column_bc] return result + security.declareProtected(Permissions.AccessContentsInformation, + 'getVariationRangeCategoryItemList') + def getVariationRangeCategoryItemList(self, base_category_list=(), base=1, + root=1, display_id='title', + display_base_category=1, + current_category=None): + """ + Returns possible variations + => [(display, value)] + """ + result = [] + if base_category_list is (): + base_category_list = self.getVariationBaseCategoryList() + elif type(base_category_list) is type('a'): + base_category_list = (base_category_list, ) + # Render categories + for base_category in base_category_list: + result += self.portal_categories.unrestrictedTraverse(base_category).\ + getCategoryChildLogicalPathItemList( + base=base, + display_base_category=display_base_category, + display_none_category=0) + # Return result + return result + + security.declareProtected(Permissions.AccessContentsInformation, + 'getVariationRangeCategoryList') + def getVariationRangeCategoryList(self, base_category_list=(), base=1, + root=1, current_category=None): + """ + Returns the range of acceptable categories + """ + vrcil = self.getVariationRangeCategoryItemList( + base_category_list=base_category_list, + base=base, root=root, + current_category=current_category) + # display is on left + return map(lambda x: x[1], vrcil) + # Context related methods security.declarePublic('newVariationValue') def newVariationValue(self, context=None, REQUEST=None, **kw): -- 2.30.9