Skip to content

Commit 58ea952

Browse files
committed
fix #5: make this question as an feature
1 parent 3406fb8 commit 58ea952

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

django_excel/__init__.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ def new_file(self, file_name, *args, **kwargs):
116116
self.content_type_extra)
117117

118118

119-
webio.ExcelResponse = HttpResponse
119+
def make_response(content, content_type, status, file_name=None):
120+
"""
121+
Custom response function that is called by pyexcel-webio
122+
"""
123+
response = HttpResponse(content, content_type=content_type, status=status)
124+
if file_name:
125+
response["Content-Disposition"] = "attachment; filename=%s" % (file_name)
126+
return response
127+
128+
129+
webio.ExcelResponse = make_response
120130

121131

122132
from pyexcel_webio import (
@@ -129,7 +139,8 @@ def new_file(self, file_name, *args, **kwargs):
129139
)
130140

131141

132-
def make_response_from_a_table(model, file_type, status=200, **keywords):
142+
def make_response_from_a_table(model, file_type,
143+
status=200, file_name=None, **keywords):
133144
"""
134145
Produce a single sheet Excel book of *file_type*
135146
@@ -138,10 +149,11 @@ def make_response_from_a_table(model, file_type, status=200, **keywords):
138149
:param status: same as :meth:`~django_excel.make_response`
139150
"""
140151
sheet = pe.get_sheet(model=model, **keywords)
141-
return make_response(sheet, file_type, status, **keywords)
152+
return make_response(sheet, file_type, status, file_name=file_name, **keywords)
142153

143154

144-
def make_response_from_tables(models, file_type, status=200, **keywords):
155+
def make_response_from_tables(models, file_type,
156+
status=200, file_name=None, **keywords):
145157
"""
146158
Produce a multiple sheet Excel book of *file_type*. It becomes the same
147159
as :meth:`~django_excel.make_response_from_a_table` if you pass *tables*
@@ -152,4 +164,4 @@ def make_response_from_tables(models, file_type, status=200, **keywords):
152164
:param status: same as :meth:`~django_excel.make_response`
153165
"""
154166
book = pe.get_book(models=models, **keywords)
155-
return make_response(book, file_type, status, **keywords)
167+
return make_response(book, file_type, status, file_name=file_name, **keywords)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pyexcel>=0.1.4
2-
pyexcel-webio>=0.0.2
2+
pyexcel-webio>=0.0.5
33
Django>=1.7.1

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
with open("README.rst", 'r') as readme:
99
README_txt = readme.read()
1010

11-
with open("requirements.txt", 'r') as requirements_txt:
12-
lines = requirements_txt.readlines()
13-
lines = map(lambda x: x.rstrip(), lines)
14-
dependencies = lines
15-
11+
dependencies=[
12+
'pyexcel>=0.1.4',
13+
'pyexcel-webio>=0.0.5',
14+
'Django>=1.7.1'
15+
]
16+
1617
with open("VERSION", "r") as version:
1718
version_txt = version.read().rstrip()
1819

testResponse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def testCustomExport(self):
217217
class ExcelResponseUsingFileTestCase(ExcelResponseTestCase):
218218
pass
219219

220+
220221
@override_settings(FILE_UPLOAD_MAX_MEMORY_SIZE=1)
221222
class DatabaseOperationsUsingFileTestCase(DatabaseOperationsTestCase):
222223
pass

test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ python-coveralls
55
coverage==3.7.1
66
pyexcel-xls
77
pyexcel-xlsx
8-
https://github.com/T0ha/ezodf/archive/2c69103e6c0715adb0e36562cb2e6325fd776112.zip
98
pyexcel-ods3
109
lxml
10+
https://github.com/pyexcel/pyexcel-webio/archive/master.zip

0 commit comments

Comments
 (0)