Stoken filtering: abstract getting the stoken id.

This commit is contained in:
Tom Hacohen 2020-06-24 11:30:37 +03:00
parent f6ef514661
commit 0a19cd7e2c

View File

@ -88,8 +88,11 @@ class BaseViewSet(viewsets.ModelViewSet):
user = self.request.user user = self.request.user
return queryset.filter(members__user=user) return queryset.filter(members__user=user)
def get_stoken_obj_id(self, request):
return request.GET.get('stoken', None)
def get_stoken_obj(self, request): def get_stoken_obj(self, request):
stoken = request.GET.get('stoken', None) stoken = self.get_stoken_obj_id(request)
if stoken is not None: if stoken is not None:
return get_object_or_404(Stoken.objects.all(), uid=stoken) return get_object_or_404(Stoken.objects.all(), uid=stoken)
@ -454,13 +457,8 @@ class CollectionMemberViewSet(BaseViewSet):
return queryset.filter(collection=collection) return queryset.filter(collection=collection)
# We override this method because we expect the stoken to be called iterator # We override this method because we expect the stoken to be called iterator
def get_stoken_obj(self, request): def get_stoken_obj_id(self, request):
stoken = request.GET.get('iterator', None) return request.GET.get('iterator', None)
if stoken is not None:
return get_object_or_404(Stoken.objects.all(), uid=stoken)
return None
def list(self, request, collection_uid=None): def list(self, request, collection_uid=None):
queryset = self.get_queryset().order_by('id') queryset = self.get_queryset().order_by('id')