Commit 5c23c367 authored by Romain Courteaud's avatar Romain Courteaud

erp5_core: do one catalog call only

Catalog seems to correctly handle the OR parameters.

Do not lose the possible external `query` parameter.
parent e97990e9
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
kw.pop('relative_url', None)
kw.pop('follow_up_uid', None)
portal_catalog=context.getPortalObject().portal_catalog
follow_up_related_document_list = portal_catalog(
portal_type=portal_type,
follow_up_uid=context.getUid(), **kw)
kw['query'] = Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_'))
if follow_up_related_document_list:
kw['query'] = ComplexQuery(
kw['query'],
Query(uid=[x.getUid() for x in follow_up_related_document_list]),
logical_operator='or')
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
return portal_catalog(portal_type=portal_type, limit=limit, **kw)
if portal_type is None:
portal_type = portal.getPortalDocumentTypeList() + portal.getPortalEmbeddedDocumentTypeList()
document_query = ComplexQuery(
Query(follow_up_uid=context.getUid()),
Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_')),
logical_operator='or'
)
if query is None:
query = document_query
else:
query = ComplexQuery(
query,
document_query,
logical_operator='and'
)
return portal_catalog(
portal_type=portal_type,
query=query,
**kw)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>portal_type=(), limit=None, **kw</string> </value>
<value> <string>portal_type=None, query=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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