]> git.parisson.com Git - telemeta.git/commitdiff
More StreamingHttpResponse
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 19 Jan 2015 00:08:55 +0000 (01:08 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 19 Jan 2015 00:08:55 +0000 (01:08 +0100)
telemeta/views/collection.py
telemeta/views/item.py
telemeta/views/resource.py

index 227a776010443fbe9a6a058007af1c399262c5c6..b059585f64119a0c2cac792e196f069144cb5c82 100644 (file)
@@ -144,7 +144,7 @@ class CollectionView(object):
     def related_media_collection_stream(self, request, public_id, media_id):
         collection = MediaCollection.objects.get(public_id=public_id)
         media = MediaCollectionRelated.objects.get(collection=collection, id=media_id)
-        response = HttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
+        response = StreamingHttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
 #        response['Content-Disposition'] = 'attachment'
         return response
 
@@ -152,7 +152,7 @@ class CollectionView(object):
         collection = MediaCollection.objects.get(public_id=public_id)
         media = MediaCollectionRelated.objects.get(collection=collection, id=media_id)
         filename = media.file.path.split(os.sep)[-1]
-        response = HttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
+        response = StreamingHttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
         response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
         return response
 
@@ -214,12 +214,7 @@ class CollectionPackageView(View):
                 path = cache_data.dir + os.sep + filename
                 z.write(path, arcname=collection.public_id + os.sep + filename)
 
-        try:
-            from django.http import StreamingHttpResponse
-            response = StreamingHttpResponse(z, content_type='application/zip')
-        except:
-            response = HttpResponse(z, content_type='application/zip')
-
+        response = StreamingHttpResponse(z, content_type='application/zip')
         response['Content-Disposition'] = "attachment; filename=%s.%s" % \
                                              (collection.code, 'zip')
         return response
index ffc4ddf8e62a1a0ffaa79062b3844beac2d0b0a8..ff196a81def35c00215a91957c7244d9dd4ff56a 100644 (file)
@@ -222,14 +222,14 @@ class ItemView(ItemBaseMixin):
         item = MediaItem.objects.get(public_id=item_public_id)
         media = MediaItemRelated.objects.get(item=item, id=media_id)
         filename = media.file.path.split(os.sep)[-1]
-        response = HttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
+        response = StreamingHttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
         return response
 
     def related_media_item_download(self, request, item_public_id, media_id):
         item = MediaItem.objects.get(public_id=item_public_id)
         media = MediaItemRelated.objects.get(item=item, id=media_id)
         filename = media.file.path.split(os.sep)[-1]
-        response = HttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
+        response = StreamingHttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
         response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
         return response
 
@@ -500,7 +500,7 @@ class ItemView(ItemBaseMixin):
                 graph.render(output=path)
                 f.close()
 
-        response = HttpResponse(self.cache_data.read_stream_bin(image_file), mimetype=mime_type)
+        response = StreamingHttpResponse(self.cache_data.read_stream_bin(image_file), mimetype=mime_type)
         return response
 
     def list_export_extensions(self):
@@ -530,14 +530,14 @@ class ItemView(ItemBaseMixin):
         if 'mp4' in extension:
             mime_type = 'video/mp4'
             video = item.file.path
-            response = HttpResponse(stream_from_file(video), mimetype = mime_type)
+            response = StreamingHttpResponse(stream_from_file(video), mimetype = mime_type)
             response['Content-Disposition'] = 'attachment'
             return response
 
         if 'webm' in extension:
             mime_type = 'video/webm'
             video = item.file.path
-            response = HttpResponse(stream_from_file(video), mimetype = mime_type)
+            response = StreamingHttpResponse(stream_from_file(video), mimetype = mime_type)
             response['Content-Disposition'] = 'attachment'
             return response
 
@@ -575,7 +575,7 @@ class ItemView(ItemBaseMixin):
                     proc.write_metadata()
                 except:
                     pass
-            response = HttpResponse(stream_from_file(source), mimetype = mime_type)
+            response = StreamingHttpResponse(stream_from_file(source), mimetype = mime_type)
         else:
             media = self.cache_export.dir + os.sep + file
             if not self.cache_export.exists(file) or not flag.value:
index 710618c4c95cb0f68a4f38e5371055c5aab0a644..4ae576cbf7a12d4a5cf256ae5125936f0f88a93d 100644 (file)
@@ -157,7 +157,7 @@ class ResourceView(object):
         self.setup(type)
         resource = self.model.objects.get(code=public_id)
         media = self.related.objects.get(resource=resource, id=media_id)
-        response = HttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
+        response = StreamingHttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
         return response
 
     def related_download(self, request, type, public_id, media_id):
@@ -165,7 +165,7 @@ class ResourceView(object):
         resource = self.model.objects.get(code=public_id)
         media = self.related.objects.get(resource=resource, id=media_id)
         filename = media.file.path.split(os.sep)[-1]
-        response = HttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
+        response = StreamingHttpResponse(stream_from_file(media.file.path), mimetype=media.mime_type)
         response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
         return response