@@ -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
122132from 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 )
0 commit comments