Commit 5f44191e authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

add flat list option to rpc.methods.collections()

parent 9278b42e
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -156,13 +156,15 @@ def collections(
    recursive: bool = False,
    limit_from: int = 0,
    limit_to: int = 2000,
    flat_list: bool = False,
) -> List[Dict]:
    """
    Return the user's collections under the parent collection
    specified by 'parent_id'. If 'parent_id' is null, will return
    collections available at root. If 'recursive' is true, will
    return all the descendants recursively in the 'children' key.
    If recursive is false, 'children' is null.
    If recursive is false, 'children' is null. If flat_list is True,
    collections are returned as a flat list and parent is not used.

    Example output:

@@ -198,6 +200,11 @@ def collections(
    if limit_to < limit_from:
        return []
    data = []
    if flat_list:
        query_set: Union[Iterator[Collection], QuerySet] = Collection.objects.filter(
            owner=user, deleted_at__isnull=True
        )[limit_from:limit_to]
    else:
        query_set: Union[Iterator[Collection], QuerySet] = Collection.objects.filter(
            owner=user, parent=parent, deleted_at__isnull=True
        )[limit_from:limit_to]