Commit 05fbafcf authored by Sebastien Robin's avatar Sebastien Robin

CMFCategory: getRelatedValueList should return documents matching any category

portal_categories.getRelatedValueList(my_document,
base_category_list=["category_1", "category_2"]) should return any document
related through category_1 or through category_2.

Before this fix, only documents having this in categories match :
category_1/path_to/my_document
category_2/path_to/my_document

There was clearly a regression, since script Organisation_jumpToRelatedObjectList
was working fine for years (it pass many base_category to getRelatedValueList), and
it was not working any more.
parent 7a3f71d8
...@@ -1352,19 +1352,20 @@ class CategoryTool(BaseTool): ...@@ -1352,19 +1352,20 @@ class CategoryTool(BaseTool):
portal_catalog = context.getPortalObject().portal_catalog portal_catalog = context.getPortalObject().portal_catalog
def search(category_list, portal_type, strict_membership): def search(category_list, portal_type, strict_membership):
inner_join_list = [] left_join_list = []
catalog_kw = { catalog_kw = {
'query': portal_catalog.getCategoryParameterDict( 'query': portal_catalog.getCategoryParameterDict(
category_list=category_list, category_list=category_list,
strict_membership=strict_membership, strict_membership=strict_membership,
onJoin=inner_join_list.append, onJoin=left_join_list.append,
logical_operator="OR"
), ),
} }
if portal_type is not None: if portal_type is not None:
catalog_kw['portal_type'] = portal_type catalog_kw['portal_type'] = portal_type
return portal_catalog.unrestrictedSearchResults( return portal_catalog.unrestrictedSearchResults(
select_list=['relative_url', 'portal_type'], select_list=['relative_url', 'portal_type'],
inner_join_list=inner_join_list, left_join_list=left_join_list,
**catalog_kw **catalog_kw
) )
result_dict = {} result_dict = {}
......
...@@ -628,6 +628,21 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -628,6 +628,21 @@ class TestCMFCategory(ERP5TypeTestCase):
self.tic() self.tic()
self.assertEqual(person.getDefaultDestinationRelated(), self.assertEqual(person.getDefaultDestinationRelated(),
'organisation_module/organisation_test' ) 'organisation_module/organisation_test' )
self.assertEqual([org], person.getRelatedValueList())
self.assertEqual([org], person.getRelatedValueList(base_category_list=["destination"]))
self.assertEqual([], person.getRelatedValueList(base_category_list=["skill"]))
self.assertEqual([org], person.getRelatedValueList(base_category_list=["destination", "skill"]))
self.assertEqual([], person.getRelatedValueList(portal_type="Person"))
self.assertEqual([org], person.getRelatedValueList(portal_type="Organisation"))
other_org = self.portal.organisation_module.newContent(
role='person_module/person_test')
self.tic()
self.assertEqual([other_org], person.getRelatedValueList(base_category_list=["role"]))
self.assertEqual([other_org], person.getRelatedValueList(
base_category_list=["role"]))
self.assertEqual(set([org, other_org]),
set(person.getRelatedValueList(base_category_list=["destination", "role"])))
def test_17_CategoriesAndDomainSelection(self): def test_17_CategoriesAndDomainSelection(self):
""" Tests Categories and Domain Selection """ """ Tests Categories and Domain Selection """
......
...@@ -1112,7 +1112,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -1112,7 +1112,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
return related_key_list return related_key_list
security.declarePublic('getCategoryValueDictParameterDict') security.declarePublic('getCategoryValueDictParameterDict')
def getCategoryValueDictParameterDict(self, base_category_dict, category_table='category', strict_membership=True, forward=True, onJoin=lambda x: None): def getCategoryValueDictParameterDict(self, base_category_dict, category_table='category', strict_membership=True, forward=True, onJoin=lambda x: None,
logical_operator='AND'):
""" """
From a mapping from base category ids to lists of documents, produce a From a mapping from base category ids to lists of documents, produce a
query tree testing (strict or not, forward or reverse relation) query tree testing (strict or not, forward or reverse relation)
...@@ -1138,6 +1139,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -1138,6 +1139,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
existing conditions for given pseudo-column. existing conditions for given pseudo-column.
This last form should very rarely be needed (ex: when joining with This last form should very rarely be needed (ex: when joining with
predicate_category table as it contains non-standard uid values). predicate_category table as it contains non-standard uid values).
logical_operator ('AND' or 'OR')
Controls the sql operator used to match categories
Return a query tree. Return a query tree.
""" """
...@@ -1196,7 +1199,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -1196,7 +1199,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
break break
parent_uid_set.add(uid) parent_uid_set.add(uid)
query_list.append(SimpleQuery(uid=parent_uid_set)) query_list.append(SimpleQuery(uid=parent_uid_set))
return ComplexQuery(query_list) return ComplexQuery(query_list, logical_operator=logical_operator)
security.declarePublic('getCategoryParameterDict') security.declarePublic('getCategoryParameterDict')
def getCategoryParameterDict(self, category_list, onMissing=lambda category: True, **kw): def getCategoryParameterDict(self, category_list, onMissing=lambda category: True, **kw):
......
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