image serve view refactor for better DRY override

pull/2583/merge
Yannick Chabbert 2016-04-07 11:53:05 +02:00 zatwierdzone przez Karl Hobley
rodzic 06af3fe33d
commit 4ae735fae2
1 zmienionych plików z 12 dodań i 9 usunięć

Wyświetl plik

@ -63,15 +63,18 @@ class ServeView(View):
except InvalidFilterSpecError:
return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)
# Serve it
if self.action == 'serve':
# Open and serve the file
rendition.file.open('rb')
image_format = imghdr.what(rendition.file)
return StreamingHttpResponse(FileWrapper(rendition.file), content_type='image/' + image_format)
elif self.action == 'redirect':
# Redirect to the file's public location
return HttpResponsePermanentRedirect(rendition.url)
return getattr(self, self.action)(rendition)
def serve(self, rendition):
# Open and serve the file
rendition.file.open('rb')
image_format = imghdr.what(rendition.file)
return StreamingHttpResponse(FileWrapper(rendition.file),
content_type='image/' + image_format)
def redirect(self, rendition):
# Redirect to the file's public location
return HttpResponsePermanentRedirect(rendition.url)
serve = ServeView.as_view()