Skip to content

Commit 4d3533c

Browse files
committed
code refactoring on pull request #8
1 parent 2f27f3f commit 4d3533c

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ python:
1111
- 3.5
1212
install:
1313
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install weakrefset; fi
14+
- pip install -r requirements.txt
1415
- pip install -r tests/requirements.txt
1516
script:
1617
make test

README.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Flask-Excel - Let you focus on data, instead of file formats
33
============================================================
44

5-
.. image:: https://api.travis-ci.org/chfw/Flask-Excel.svg?branch=master
5+
.. image:: https://api.travis-ci.org/pyexcel/Flask-Excel.svg?branch=master
66
:target: http://travis-ci.org/chfw/Flask-Excel
77

88
.. image:: https://coveralls.io/repos/chfw/Flask-Excel/badge.svg
@@ -11,9 +11,6 @@ Flask-Excel - Let you focus on data, instead of file formats
1111
.. image:: https://readthedocs.org/projects/flask-excel/badge/?version=latest
1212
:target: http://flask-excel.readthedocs.org/en/latest/
1313

14-
.. image:: http://img.shields.io/gittip/chfw.svg
15-
:target: https://gratipay.com/chfw/
16-
1714
**Flask-Excel** is based on `pyexcel <https://github.com/chfw/pyexcel>`_ and makes
1815
it easy to consume/produce information stored in excel files over HTTP protocol as
1916
well as on file system. This library can turn the excel data into a list of lists,

flask_excel/__init__.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,42 @@
1212
import pyexcel as pe
1313
import pyexcel_webio as webio
1414

15+
1516
class ExcelRequest(webio.ExcelInputInMultiDict, Request):
17+
"""
18+
Mix in pyexcel's webio function signatures to Flask request
19+
"""
1620
def get_file_tuple(self, field_name):
1721
filehandle = self.files[field_name]
1822
filename = filehandle.filename
1923
extension = filename.split(".")[1]
2024
return extension, filehandle
2125

26+
27+
# Plug-in the custom request to Flask
2228
Flask.request_class = ExcelRequest
23-
webio.ExcelResponse = Response
2429

25-
def add_file_name(response, file_name, file_type):
30+
31+
def make_response(content, content_type, status, file_name=None):
32+
"""
33+
Custom response function that is called by pyexcel-webio
34+
"""
35+
response = Response(content, content_type=content_type, status=status)
2636
if file_name:
27-
response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (file_name, file_type)
37+
response.headers["Content-Disposition"] = "attachment; filename=%s" % (file_name)
2838
return response
2939

30-
def make_response(pyexcel_instance, file_type, status=200, file_name=None, **keywords):
31-
return add_file_name(webio.make_response(pyexcel_instance, file_type, status=status, **keywords), file_name, file_type)
32-
33-
def make_response_from_array(array, file_type, status=200, file_name=None, **keywords):
34-
return add_file_name(webio.make_response_from_array(array, file_type, status=status, **keywords), file_name, file_type)
35-
36-
def make_response_from_dict(adict, file_type, status=200, file_name=None, **keywords):
37-
return add_file_name(webio.make_response_from_dict(adict, file_type, status=status, **keywords), file_name, file_type)
38-
39-
def make_response_from_records(records, file_type, status=200, file_name=None, **keywords):
40-
return add_file_name(webio.make_response_from_records(records, file_type, status=status, **keywords), file_name, file_type)
41-
42-
def make_response_from_book_dict(adict, file_type, status=200, file_name=None, **keywords):
43-
return add_file_name(webio.make_response_from_book_dict(adict, file_type, status=status, **keywords), file_name, file_type)
44-
45-
def make_response_from_a_table(session, table, file_type, status=200, file_name=None, **keywords):
46-
return add_file_name(webio.make_response_from_a_table(session, table, file_type, status=status, **keywords), file_name, file_type)
4740

48-
def make_response_from_query_sets(query_sets, column_names, file_type, status=200, file_name=None, **keywords):
49-
return add_file_name(webio.make_response_from_query_sets(query_sets, column_names, file_type, status=status, **keywords), file_name, file_type)
41+
webio.ExcelResponse = make_response
5042

51-
def make_response_from_tables(session, tables, file_type, status=200, file_name=None, **keywords):
52-
return add_file_name(webio.make_response_from_tables(session, tables, file_type, status=status, **keywords), file_name, file_type)
5343

54-
__VERSION__ = '0.0.4'
44+
from pyexcel_webio import (
45+
make_response,
46+
make_response_from_array,
47+
make_response_from_dict,
48+
make_response_from_records,
49+
make_response_from_book_dict,
50+
make_response_from_a_table,
51+
make_response_from_query_sets,
52+
make_response_from_tables
53+
)

tests/requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ coverage==3.7.1
88
pyexcel>=0.1.7
99
pyexcel-io>=0.0.8
1010
pyexcel-ods3>=0.0.8
11-
pyexcel-webio>=0.0.3
11+
https://github.com/pyexcel/pyexcel-webio/archive/master.zip
1212
pyexcel-xls>=0.0.7
1313
pyexcel-xlsx>=0.0.7
14-
https://github.com/T0ha/ezodf/archive/2c69103e6c0715adb0e36562cb2e6325fd776112.zip
15-
lxml

0 commit comments

Comments
 (0)