"doc/integration/jira/jira_server_configuration.md" did not exist on "34d1d738960e81a0cb48952a4dcb9bc9993b1b66"
Commit 3df9d7ca authored by Alexandre Boeglin's avatar Alexandre Boeglin

Add support for individual variations in Resource and Variated API.

Original work by Daniel Feliubadalo and Romain Courteaud.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20291 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1041f3f4
...@@ -82,7 +82,8 @@ class Resource(XMLMatrix, Variated): ...@@ -82,7 +82,8 @@ class Resource(XMLMatrix, Variated):
def getVariationRangeCategoryItemList(self, base_category_list=(), base=1, def getVariationRangeCategoryItemList(self, base_category_list=(), base=1,
root=1, display_id='title', root=1, display_id='title',
display_base_category=1, display_base_category=1,
current_category=None, **kw): current_category=None,
omit_individual_variation=0, **kw):
""" """
Returns possible variations Returns possible variations
...@@ -113,41 +114,40 @@ class Resource(XMLMatrix, Variated): ...@@ -113,41 +114,40 @@ class Resource(XMLMatrix, Variated):
""" """
result = [] result = []
if base_category_list is (): if base_category_list is ():
base_category_list = self.getVariationBaseCategoryList() base_category_list = self.getVariationBaseCategoryList(
elif type(base_category_list) is type('a'): omit_individual_variation=omit_individual_variation)
elif isinstance(base_category_list, str):
base_category_list = (base_category_list,) base_category_list = (base_category_list,)
individual_variation_list = self.searchFolder(
portal_type=self.getPortalVariationTypeList(),
sort_on=[('title','ascending')])
individual_variation_list = [x.getObject() for x in
individual_variation_list]
other_base_category_dict = dict([(i,1) for i in base_category_list]) other_base_category_dict = dict([(i,1) for i in base_category_list])
other_variations = self.searchFolder( \
portal_type=self.getPortalVariationTypeList(), if not omit_individual_variation:
sort_on=[('title','ascending')]) for variation in individual_variation_list:
other_variations = [x.getObject() for x in other_variations] for base_category in variation.getVariationBaseCategoryList():
other_variations = [x for x in other_variations if x is not None] if base_category_list is ()\
or base_category in base_category_list:
for object in other_variations: other_base_category_dict[base_category] = 0
for base_category in object.getVariationBaseCategoryList(): # XXX now, call Renderer a lot of time.
if (base_category_list is ()) or \ # Better implementation needed
(base_category in base_category_list): result.extend(Renderer(
other_base_category_dict[base_category] = 0 base_category=base_category,
# XXX now, call Renderer a lot of time. display_base_category=display_base_category,
# Better implementation needed display_none_category=0, base=base,
result.extend(Renderer( current_category=current_category,
base_category=base_category, display_id=display_id).render([variation]))
display_base_category=display_base_category,
display_none_category=0, base=base, other_base_category_list = [x for x, y in
current_category=current_category, other_base_category_dict.iteritems() if y == 1]
display_id=display_id).\
render([object]))
other_base_category_item_list = filter(lambda x: x[1]==1,
other_base_category_dict.items())
other_base_category_list = map(lambda x: x[0],
other_base_category_item_list)
# Get category variation # Get category variation
if len(other_base_category_list) != 0: if other_base_category_list:
result += Variated.getVariationRangeCategoryItemList( result.extend(Variated.getVariationRangeCategoryItemList(
self, base_category_list=other_base_category_list, self, base_category_list=other_base_category_list,
base=base, display_base_category=display_base_category, **kw) base=base, display_base_category=display_base_category, **kw))
# Return result # Return result
return result return result
...@@ -169,31 +169,37 @@ class Resource(XMLMatrix, Variated): ...@@ -169,31 +169,37 @@ class Resource(XMLMatrix, Variated):
*old parameters: base=1, current_category=None, *old parameters: base=1, current_category=None,
display_id='getTitle' (default value getTitleOrId) display_id='getTitle' (default value getTitleOrId)
""" """
base_category_list = base_category_list or \
self.getVariationBaseCategoryList()
individual_bc_list = self.getIndividualVariationBaseCategoryList()
other_bc_list = [x for x in base_category_list if x not
in individual_bc_list]
result = Variated.getVariationCategoryItemList(self, result = Variated.getVariationCategoryItemList(self,
base_category_list=base_category_list, base_category_list=other_bc_list,
display_base_category=display_base_category, display_base_category=display_base_category,
display_id=display_id, base=base, **kw) display_id=display_id, base=base, **kw)
if not omit_individual_variation: if not omit_individual_variation:
other_variations = self.searchFolder( individual_variation_list = self.searchFolder(
portal_type=self.getPortalVariationTypeList()) portal_type=self.getPortalVariationTypeList())
individual_variation_list = [x.getObject() for x in
other_variations = map(lambda x: x.getObject(), other_variations) individual_variation_list]
other_variations = filter(lambda x: x is not None, other_variations)
for variation in individual_variation_list:
for object in other_variations: for base_category in variation.getVariationBaseCategoryList():
for base_category in object.getVariationBaseCategoryList(): if (base_category_list is () or base_category in
if (base_category_list is ()) or \ base_category_list) and base_category in individual_bc_list:
(base_category in base_category_list):
# XXX append object, relative_url ? # XXX append object, relative_url ?
# XXX now, call Renderer a lot of time. # XXX now, call Renderer a lot of time.
# Better implementation needed # Better implementation needed
result.extend(Renderer( result.extend(Renderer(
base_category=base_category, base_category=base_category,
display_base_category=display_base_category, display_base_category=display_base_category,
display_none_category=0, base=base, display_none_category=0, base=base,
current_category=current_category, current_category=current_category, display_id=display_id,
display_id=display_id, **kw).\ **kw).render([variation]))
render([object]))
return result return result
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -231,7 +237,7 @@ class Resource(XMLMatrix, Variated): ...@@ -231,7 +237,7 @@ class Resource(XMLMatrix, Variated):
vcil = self.getVariationCategoryItemList( vcil = self.getVariationCategoryItemList(
base_category_list=base_category_list, base_category_list=base_category_list,
omit_individual_variation=omit_individual_variation,**kw) omit_individual_variation=omit_individual_variation,**kw)
return map(lambda x: x[1], vcil) return [x[1] for x in vcil]
# Unit conversion # Unit conversion
security.declareProtected(Permissions.AccessContentsInformation, 'convertQuantity') security.declareProtected(Permissions.AccessContentsInformation, 'convertQuantity')
......
...@@ -62,7 +62,7 @@ class Variated(Base): ...@@ -62,7 +62,7 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryList') 'getVariationBaseCategoryList')
def getVariationBaseCategoryList(self, omit_optional_variation=0, def getVariationBaseCategoryList(self, omit_optional_variation=0,
omit_option_base_category=None): omit_option_base_category=None, omit_individual_variation=0):
""" """
Return the list of variation base category. Return the list of variation base category.
If omit_optional_variation==1, do not include base category If omit_optional_variation==1, do not include base category
...@@ -81,6 +81,12 @@ class Variated(Base): ...@@ -81,6 +81,12 @@ class Variated(Base):
# of a good API. # of a good API.
option_base_category_list = self.getPortalOptionBaseCategoryList() option_base_category_list = self.getPortalOptionBaseCategoryList()
vbcl = [x for x in vbcl if x not in option_base_category_list] vbcl = [x for x in vbcl if x not in option_base_category_list]
else:
vbcl.extend(self.getOptionalVariationBaseCategoryList())
if omit_individual_variation == 0:
vbcl.extend(self.getIndividualVariationBaseCategoryList())
return vbcl return vbcl
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -222,7 +228,8 @@ class Variated(Base): ...@@ -222,7 +228,8 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationBaseCategoryItemList') 'getVariationBaseCategoryItemList')
def getVariationBaseCategoryItemList(self, display_id='title_or_id', def getVariationBaseCategoryItemList(self, display_id='title_or_id',
omit_optional_variation=0, omit_option_base_category=None): omit_optional_variation=0, omit_option_base_category=None,
omit_individual_variation=0):
""" """
Returns base category of the resource Returns base category of the resource
as a list of tuples (title, id). This is mostly as a list of tuples (title, id). This is mostly
...@@ -236,7 +243,8 @@ class Variated(Base): ...@@ -236,7 +243,8 @@ class Variated(Base):
omit_optional_variation = omit_option_base_category omit_optional_variation = omit_option_base_category
variation_base_category_list = self.getVariationBaseCategoryList( variation_base_category_list = self.getVariationBaseCategoryList(
omit_optional_variation=omit_optional_variation) omit_optional_variation=omit_optional_variation,
omit_individual_variation=omit_individual_variation)
result = [] result = []
for base_category in variation_base_category_list: for base_category in variation_base_category_list:
bc = self.portal_categories.resolveCategory(base_category) bc = self.portal_categories.resolveCategory(base_category)
...@@ -348,16 +356,18 @@ class Variated(Base): ...@@ -348,16 +356,18 @@ class Variated(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getVariationRangeCategoryList') 'getVariationRangeCategoryList')
def getVariationRangeCategoryList(self, base_category_list=(), base=1, def getVariationRangeCategoryList(self, base_category_list=(), base=1,
root=1, current_category=None): root=1, current_category=None,
omit_individual_variation=0):
""" """
Returns the range of acceptable categories Returns the range of acceptable categories
""" """
vrcil = self.getVariationRangeCategoryItemList( vrcil = self.getVariationRangeCategoryItemList(
base_category_list=base_category_list, base_category_list=base_category_list,
base=base, root=root, base=base, root=root,
current_category=current_category) current_category=current_category,
omit_individual_variation=omit_individual_variation)
# display is on left # display is on left
return map(lambda x: x[1], vrcil) return [x[1] for x in vrcil]
# Context related methods # Context related methods
security.declarePublic('newVariationValue') security.declarePublic('newVariationValue')
......
This diff is collapsed.
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