From 7d864594802b5f7f0d8e23ab383f37e68a79df79 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Fri, 25 Dec 2020 11:53:11 +0200 Subject: [PATCH] collection.pyL list_multi --- etebase_fastapi/collection.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/etebase_fastapi/collection.py b/etebase_fastapi/collection.py index ec0125d..7c9aca8 100644 --- a/etebase_fastapi/collection.py +++ b/etebase_fastapi/collection.py @@ -10,6 +10,7 @@ from asgiref.sync import sync_to_async from django_etebase.models import Collection, Stoken, AccessLevels, CollectionMember from .authentication import get_authenticated_user from .msgpack import MsgpackRoute, MsgpackResponse +from .stoken_handler import filter_by_stoken_and_limit, filter_by_stoken, get_queryset_stoken User = get_user_model() collection_router = APIRouter(route_class=MsgpackRoute) @@ -51,9 +52,11 @@ class ListResponse(BaseModel): @sync_to_async -def list_common(queryset: QuerySet, stoken: t.Optional[str], user: User) -> MsgpackResponse: +def list_common(queryset: QuerySet, user: User, stoken: t.Optional[str], limit: int) -> MsgpackResponse: + result, new_stoken_obj, done = filter_by_stoken_and_limit(stoken, limit, queryset, Collection.stoken_annotation) + new_stoken = new_stoken_obj and new_stoken_obj.uid data: t.List[CollectionOut] = [CollectionOut.from_orm_user(item, user) for item in queryset] - ret = ListResponse(data=data, stoken=stoken, done=True) + ret = ListResponse(data=data, stoken=new_stoken, done=done) return MsgpackResponse(content=ret) @@ -62,11 +65,13 @@ def get_collection_queryset(user: User, queryset: QuerySet) -> QuerySet: @collection_router.post("/list_multi/") -async def list_multi(limit: int, data: ListMulti, user: User = Depends(get_authenticated_user)): +async def list_multi( + data: ListMulti, stoken: t.Optional[str] = None, limit: int = 50, user: User = Depends(get_authenticated_user) +): queryset = get_collection_queryset(user, default_queryset) # FIXME: Remove the isnull part once we attach collection types to all objects ("collection-type-migration") queryset = queryset.filter( Q(members__collectionType__uid__in=data.collectionTypes) | Q(members__collectionType__isnull=True) ) - response = await list_common(queryset, None, user) + response = await list_common(queryset, user, stoken, limit) return response