Пример #1
0
 def list(self, request):
     try:
         page_number = int(request.GET.get('page_number'))
         items_per_page = int(request.GET.get('per_page'))
         offset = (page_number - 1) * items_per_page
         user_id = request.user.id  
         results = ExportFile.objects(owner_id=user_id).exclude("file").skip(offset).limit(items_per_page).order_by('-updated_date')
         count = ExportFile.objects(owner_id=user_id).count()
         serializedList = ExportFilesSerializer(results, many=True)
         return JsonResponse({'results' : serializedList.data, 'count': count})
     except Exception as e:
             return Response(str(e))    
Пример #2
0
 def list(self, request, file_id):
     try:
         user_id = request.user.id  
         result = ExportFile.objects(Q(owner_id=user_id) & Q(id=ObjectId(file_id))).first()
         if result is None:
             return JsonResponse({'Error' : 'File not found to download'})
         export_file = result.file
         chunk_size = 8192
         response = StreamingHttpResponse(FileWrapper(export_file, chunk_size), content_type=result['type'])
         response['Content-Disposition'] = "attachment; filename=%s" % os.path.basename(result['file_name'])
         return response
     except Exception as e:
             return Response(str(e))