Skip to content

Commit fad3186

Browse files
committed
support multiple app and try to confirm with flask-extension guide. and will try to become a registered flask extension
1 parent 4c3041c commit fad3186

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

.moban.d/docs/source/index.rst.jj2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ In your application, you must import it before using it::
77

88
import flask_excel as excel
99

10+
...
11+
excel.init_excel(app) # required since version 0.0.8
12+
1013
{%endblock%}
1114

1215
{%block quick_start%}

docs/source/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:Source code: http://github.com/pyexcel/Flask-Excel.git
1111
:Issues: http://github.com/pyexcel/Flask-Excel/issues
1212
:License: New BSD License
13+
:Development: |release|
1314
:Released: |version|
1415
:Generated: |today|
1516

@@ -157,6 +158,9 @@ In your application, you must import it before using it::
157158

158159
import flask_excel as excel
159160

161+
...
162+
excel.init_excel(app) # required since version 0.0.8
163+
160164

161165
Quick start
162166
--------------------------------------------------------------------------------
@@ -188,6 +192,8 @@ http response. If you would like to give 'tsvz' a go, please change "csv" to
188192

189193

190194

195+
196+
191197
Support the project
192198
-----------------------
193199

examples/database_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import flask_excel as excel
88

99
app = Flask(__name__)
10+
excel.init_excel(app)
1011

1112

1213
@app.route("/upload", methods=['GET', 'POST'])
@@ -29,8 +30,7 @@ def download_file():
2930

3031
from flask.ext.sqlalchemy import SQLAlchemy # noqa
3132
from datetime import datetime # noqa
32-
# please uncomment the following line if you use pyexcel < 0.2.2
33-
# import pyexcel.ext.xls
33+
3434
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp.db'
3535
db = SQLAlchemy(app)
3636

examples/database_example_formatted.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# import pyexcel.ext.xls
1212

1313
app = Flask(__name__)
14-
14+
excel.init_excel(app)
1515
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp.db'
1616
db = SQLAlchemy(app)
1717

examples/tiny_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ def download_file_named_in_unicode():
4343

4444
# insert database related code here
4545
if __name__ == "__main__":
46+
excel.init_excel(app)
4647
app.run()

flask_excel/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from urllib.parse import quote
1818
_PY_VERSION = 3
1919

20-
from flask import Flask, Request, Response
20+
from flask import Request, Response
2121
import pyexcel_webio as webio
2222

2323

@@ -37,10 +37,6 @@ def get_file_tuple(self, field_name):
3737
return extension, filehandle
3838

3939

40-
# Plug-in the custom request to Flask
41-
Flask.request_class = ExcelRequest
42-
43-
4440
def _make_response(content, content_type, status, file_name=None):
4541
"""
4642
Custom response function that is called by pyexcel-webio
@@ -57,9 +53,6 @@ def _make_response(content, content_type, status, file_name=None):
5753
return response
5854

5955

60-
webio.ExcelResponse = _make_response
61-
62-
6356
from pyexcel_webio import ( # noqa
6457
make_response,
6558
make_response_from_array,
@@ -70,3 +63,9 @@ def _make_response(content, content_type, status, file_name=None):
7063
make_response_from_query_sets,
7164
make_response_from_tables
7265
)
66+
67+
68+
def init_excel(app):
69+
app.request_class = ExcelRequest
70+
webio.init_webio(_make_response)
71+
return app

tests/testapp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
else:
1919
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
2020
db = SQLAlchemy(app)
21+
excel.init_excel(app)
2122

2223

2324
class Post(db.Model):

0 commit comments

Comments
 (0)