subset documents can be queried based on combination of asset id and subset names

This commit is contained in:
Jakub Trllo 2022-07-01 10:48:33 +02:00
parent 91e5f5aa27
commit 7dc7bde293

View file

@ -381,6 +381,7 @@ def get_subsets(
subset_ids=None,
subset_names=None,
asset_ids=None,
names_by_asset_ids=None,
archived=False,
fields=None
):
@ -396,6 +397,9 @@ def get_subsets(
Filter ignored if 'None' is passed.
asset_ids (list[str|ObjectId]): Asset ids under which should look for
the subsets. Filter ignored if 'None' is passed.
names_by_asset_ids (dict[ObjectId, list[str]]): Complex filtering
using asset ids and list of subset names under the asset.
archived (bool): Look for archived subsets too.
fields (list[str]): Fields that should be returned. All fields are
returned if 'None' is passed.
@ -429,6 +433,18 @@ def get_subsets(
return []
query_filter["name"] = {"$in": list(subset_names)}
if names_by_asset_ids is not None:
or_query = []
for asset_id, names in names_by_asset_ids.items():
if asset_id and names:
or_query.append({
"parent": _convert_id(asset_id),
"name": {"$in": list(names)}
})
if not or_query:
return []
query_filter["$or"] = or_query
conn = _get_project_connection(project_name)
return conn.find(query_filter, _prepare_fields(fields))