Chunk view: unify how we get the wanted collection queryset.

This commit is contained in:
Tom Hacohen 2020-02-20 17:33:34 +02:00
parent 24cb6ed6ee
commit 0a40a04d3b

View File

@ -165,9 +165,11 @@ class CollectionItemChunkViewSet(viewsets.ViewSet):
serializer_class = CollectionItemChunkSerializer serializer_class = CollectionItemChunkSerializer
lookup_field = 'uid' 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): 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(self.get_collection_queryset(), uid=collection_uid)
col = get_object_or_404(Collection.objects, uid=collection_uid)
col_it = get_object_or_404(col.items, uid=collection_item_uid) col_it = get_object_or_404(col.items, uid=collection_item_uid)
serializer = self.serializer_class(data=request.data) serializer = self.serializer_class(data=request.data)
@ -187,7 +189,7 @@ class CollectionItemChunkViewSet(viewsets.ViewSet):
import os import os
from django.views.static import serve 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) col_it = get_object_or_404(col.items, uid=collection_item_uid)
chunk = get_object_or_404(col_it.chunks, uid=uid) chunk = get_object_or_404(col_it.chunks, uid=uid)