]> git.parisson.com Git - telemeta.git/commitdiff
add 404 for empty related media.file
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 25 May 2015 20:53:58 +0000 (22:53 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 25 May 2015 20:53:58 +0000 (22:53 +0200)
telemeta/views/resource.py

index 8cefcea7fdfe948535da2249633587e183836d6e..d30127c823f082aee30e033b615050903c60af6d 100644 (file)
@@ -157,16 +157,22 @@ 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 = StreamingHttpResponse(stream_from_file(media.file.path), content_type=media.mime_type)
+        if media.file:
+            response = StreamingHttpResponse(stream_from_file(media.file.path), content_type=media.mime_type)
+        else:
+            raise Http404
         return response
 
     def related_download(self, request, type, public_id, media_id):
         self.setup(type)
         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 = StreamingHttpResponse(stream_from_file(media.file.path), content_type=media.mime_type)
-        response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
+        if media.file:
+            filename = media.file.path.split(os.sep)[-1]
+            response = StreamingHttpResponse(stream_from_file(media.file.path), content_type=media.mime_type)
+            response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
+        else:
+            raise Http404
         return response