Rename inline to prefetch and have it on by default.

This commit is contained in:
Tom Hacohen 2020-06-24 15:55:36 +03:00
parent c21c6af1d7
commit cbb1d81850
2 changed files with 5 additions and 6 deletions

View File

@ -83,8 +83,7 @@ class CollectionContentField(BinaryBase64Field):
class ChunksField(serializers.RelatedField): class ChunksField(serializers.RelatedField):
def to_representation(self, obj): def to_representation(self, obj):
obj = obj.chunk obj = obj.chunk
inline = self.context.get('inline', False) if self.context.get('prefetch'):
if inline:
with open(obj.chunkFile.path, 'rb') as f: with open(obj.chunkFile.path, 'rb') as f:
return (obj.uid, b64encode(f.read())) return (obj.uid, b64encode(f.read()))
else: else:

View File

@ -167,8 +167,8 @@ class CollectionViewSet(BaseViewSet):
def get_serializer_context(self): def get_serializer_context(self):
context = super().get_serializer_context() context = super().get_serializer_context()
inline = 'inline' in self.request.query_params prefetch = self.request.query_params.get('prefetch', True)
context.update({'request': self.request, 'inline': inline}) context.update({'request': self.request, 'prefetch': prefetch})
return context return context
def destroy(self, request, uid=None): def destroy(self, request, uid=None):
@ -239,8 +239,8 @@ class CollectionItemViewSet(BaseViewSet):
def get_serializer_context(self): def get_serializer_context(self):
context = super().get_serializer_context() context = super().get_serializer_context()
inline = 'inline' in self.request.query_params prefetch = self.request.query_params.get('prefetch', True)
context.update({'request': self.request, 'inline': inline}) context.update({'request': self.request, 'prefetch': prefetch})
return context return context
def create(self, request, collection_uid=None): def create(self, request, collection_uid=None):