Fix Excel download of ordering batch, per python3

This commit is contained in:
Lance Edgar 2019-01-21 17:11:12 -06:00
parent 5a96672d79
commit 318e8645b2
2 changed files with 7 additions and 10 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
# Copyright © 2010-2019 Lance Edgar
#
# This file is part of Rattail.
#
@ -110,7 +110,9 @@ class View(object):
if not os.path.exists(path):
return self.notfound()
response = FileResponse(path, request=self.request)
response.headers[b'Content-Length'] = six.binary_type(os.path.getsize(path))
filename = os.path.basename(path).encode('ascii', 'replace')
response.headers[b'Content-Disposition'] = b'attachment; filename="{}"'.format(filename)
response.content_length = os.path.getsize(path)
filename = os.path.basename(path)
if six.PY2:
filename = filename.encode('ascii', 'replace')
response.content_disposition = str('attachment; filename="{}"'.format(filename))
return response

View file

@ -36,8 +36,6 @@ from rattail.db import model, api
from rattail.core import Object
from rattail.time import localtime
from pyramid.response import FileResponse
from tailbone.views.purchasing import PurchasingBatchView
@ -354,10 +352,7 @@ class OrderingBatchView(PurchasingBatchView):
path = batch.filepath(self.rattail_config, filename)
workbook.save(path)
response = FileResponse(path, request=self.request)
response.content_length = os.path.getsize(path)
response.content_disposition = b'attachment; filename="{}"'.format(filename)
return response
return self.file_response(path)
@classmethod
def _ordering_defaults(cls, config):