From 0a40a04d3bc0ec765f6be36b46bcfd55056207fb Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 20 Feb 2020 17:33:34 +0200 Subject: [PATCH] Chunk view: unify how we get the wanted collection queryset. --- django_etesync/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django_etesync/views.py b/django_etesync/views.py index f44f79a..1e97b4f 100644 --- a/django_etesync/views.py +++ b/django_etesync/views.py @@ -165,9 +165,11 @@ class CollectionItemChunkViewSet(viewsets.ViewSet): serializer_class = CollectionItemChunkSerializer lookup_field = 'uid' + def get_collection_queryset(self, queryset=Collection.objects): + return queryset.all() + def create(self, request, collection_uid=None, collection_item_uid=None): - # FIXME: we are potentially not getting the correct queryset - col = get_object_or_404(Collection.objects, uid=collection_uid) + col = get_object_or_404(self.get_collection_queryset(), uid=collection_uid) col_it = get_object_or_404(col.items, uid=collection_item_uid) serializer = self.serializer_class(data=request.data) @@ -187,7 +189,7 @@ class CollectionItemChunkViewSet(viewsets.ViewSet): import os from django.views.static import serve - col = get_object_or_404(Collection.objects, uid=collection_uid) + col = get_object_or_404(self.get_collection_queryset(), uid=collection_uid) col_it = get_object_or_404(col.items, uid=collection_item_uid) chunk = get_object_or_404(col_it.chunks, uid=uid)