Skip to content

Commit

Permalink
Add catalog parameter on content.uuidsToObjects, `content.uuidsTo…
Browse files Browse the repository at this point in the history
…Object`, `content.uuidsToCatalogBrains` and `uuidsToCatalogBrain` to allow query on other catalogs (e.g. uid_catalog)
  • Loading branch information
mpeeters committed Aug 17, 2023
1 parent 6408daf commit fc8bbf6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,10 @@ Changelog
0.74 (unreleased)
-----------------

- Nothing changed yet.
- Add `catalog` parameter on `content.uuidsToObjects`, `content.uuidsToObject`,
`content.uuidsToCatalogBrains` and `uuidsToCatalogBrain` to allow query on
other catalogs (e.g. uid_catalog)
[mpeeters]


0.73 (2023-07-20)
Expand Down
27 changes: 19 additions & 8 deletions src/imio/helpers/content.py
Expand Up @@ -352,14 +352,15 @@ def uuidsToCatalogBrains(uuids=[],
ordered=False,
query={},
check_contained_uids=False,
unrestricted=False):
unrestricted=False,
catalog='portal_catalog'):
""" Given a list of UUIDs, attempt to return catalog brains,
keeping original uuids list order if p_ordered=True.
If p_check_contained_uids=True, if we do not find brains using the UID
index, we will try to get it using the contained_uids index, used when
subelements are not indexed."""

catalog = api.portal.get_tool('portal_catalog')
catalog = api.portal.get_tool(catalog)
searcher = catalog.searchResults
if unrestricted:
searcher = catalog.unrestrictedSearchResults
Expand All @@ -382,14 +383,16 @@ def uuidToCatalogBrain(uuid,
ordered=False,
query={},
check_contained_uids=False,
unrestricted=False):
unrestricted=False,
catalog='portal_catalog'):
"""Shortcut to call uuidsToCatalogBrains to get one single element."""
res = uuidsToCatalogBrains(
uuids=[uuid],
ordered=ordered,
query=query,
check_contained_uids=check_contained_uids,
unrestricted=unrestricted)
unrestricted=unrestricted,
catalog=catalog)
if res:
res = res[0]
return res
Expand All @@ -411,7 +414,12 @@ def get_objs(container, objs=[]):
return get_objs(obj)


def uuidsToObjects(uuids=[], ordered=False, query={}, check_contained_uids=False, unrestricted=False):
def uuidsToObjects(uuids=[],
ordered=False,
query={},
check_contained_uids=False,
unrestricted=False,
catalog='portal_catalog'):
""" Given a list of UUIDs, attempt to return content objects,
keeping original uuids list order if p_ordered=True.
If p_check_contained_uids=True, if we do not find brains using the UID
Expand All @@ -422,7 +430,8 @@ def uuidsToObjects(uuids=[], ordered=False, query={}, check_contained_uids=False
ordered=not check_contained_uids and ordered or False,
query=query,
check_contained_uids=check_contained_uids,
unrestricted=unrestricted)
unrestricted=unrestricted,
catalog=catalog)
res = []
if check_contained_uids:
need_reorder = False
Expand Down Expand Up @@ -450,14 +459,16 @@ def uuidToObject(uuid,
ordered=False,
query={},
check_contained_uids=False,
unrestricted=False):
unrestricted=False,
catalog='portal_catalog'):
"""Shortcut to call uuidsToObjects to get one single element."""
res = uuidsToObjects(
uuids=[uuid],
ordered=ordered,
query=query,
check_contained_uids=check_contained_uids,
unrestricted=unrestricted)
unrestricted=unrestricted,
catalog=catalog)
if res:
res = res[0]
else:
Expand Down

0 comments on commit fc8bbf6

Please sign in to comment.