fix pictures
This commit is contained in:
parent
c11979083c
commit
9e3ed81731
|
@ -80,20 +80,16 @@ class PictureViewMixin(SingleObjectMixin):
|
||||||
# alright, continue with the request
|
# alright, continue with the request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_picture_response(self):
|
def get_picture_response(self, path):
|
||||||
if 'runserver' in sys.argv or 'runserver_plus' in sys.argv:
|
if 'runserver' in sys.argv or 'runserver_plus' in sys.argv:
|
||||||
# this is a local devserver situation, guess mimetype from extension and return picture directly
|
# this is a local devserver situation, guess mimetype from extension and return picture directly
|
||||||
response = HttpResponse(self.picture, content_type=mimetypes.types_map[".%s" % self.picture.name.split(".")[-1]])
|
response = HttpResponse(self.picture, content_type=mimetypes.types_map[".%s" % self.picture.name.split(".")[-1]])
|
||||||
else:
|
else:
|
||||||
# make nginx serve the picture using X-Accel-Redirect
|
# make nginx serve the picture using X-Accel-Redirect
|
||||||
# (this works for nginx only, other webservers use x-sendfile)
|
# (this works for nginx only, other webservers use x-sendfile)
|
||||||
# maybe make the header name configurable
|
# TODO: maybe make the header name configurable
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
response['X-Accel-Redirect'] = '/public/speakerproposals/%(campslug)s/%(proposaluuid)s/%(filename)s' % {
|
response['X-Accel-Redirect'] = path
|
||||||
'campslug': self.camp.slug,
|
|
||||||
'proposaluuid': self.get_object().uuid,
|
|
||||||
'filename': os.path.basename(self.picture.name),
|
|
||||||
}
|
|
||||||
response['Content-Type'] = ''
|
response['Content-Type'] = ''
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,12 @@ class SpeakerProposalPictureView(LoginRequiredMixin, CampViewMixin, EnsureUserOw
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
# get and return the response
|
# get and return the response
|
||||||
response = self.get_picture_response()
|
response = self.get_picture_response('/public/speakerproposals/%(campslug)s/%(proposaluuid)s/%(filename)s' % {
|
||||||
|
'campslug': self.camp.slug,
|
||||||
|
'proposaluuid': self.get_object().uuid,
|
||||||
|
'filename': os.path.basename(self.picture.name),
|
||||||
|
})
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,7 +149,12 @@ class SpeakerPictureView(CampViewMixin, PictureViewMixin, DetailView):
|
||||||
model = models.Speaker
|
model = models.Speaker
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
response = self.get_picture_response()
|
# get and return the response
|
||||||
|
response = self.get_picture_response(path='/public/speakers/%(campslug)s/%(slug)s/%(filename)s' % {
|
||||||
|
'campslug': self.camp.slug,
|
||||||
|
'slug': self.get_object().slug,
|
||||||
|
'filename': os.path.basename(self.picture.name),
|
||||||
|
})
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue