fix pictures
This commit is contained in:
parent
c11979083c
commit
9e3ed81731
|
@ -80,20 +80,16 @@ class PictureViewMixin(SingleObjectMixin):
|
|||
# alright, continue with the request
|
||||
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:
|
||||
# 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]])
|
||||
else:
|
||||
# make nginx serve the picture using X-Accel-Redirect
|
||||
# (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['X-Accel-Redirect'] = '/public/speakerproposals/%(campslug)s/%(proposaluuid)s/%(filename)s' % {
|
||||
'campslug': self.camp.slug,
|
||||
'proposaluuid': self.get_object().uuid,
|
||||
'filename': os.path.basename(self.picture.name),
|
||||
}
|
||||
response['X-Accel-Redirect'] = path
|
||||
response['Content-Type'] = ''
|
||||
return response
|
||||
|
||||
|
|
|
@ -86,7 +86,12 @@ class SpeakerProposalPictureView(LoginRequiredMixin, CampViewMixin, EnsureUserOw
|
|||
raise Http404()
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
@ -144,7 +149,12 @@ class SpeakerPictureView(CampViewMixin, PictureViewMixin, DetailView):
|
|||
model = models.Speaker
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue