This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·77 lines (61 loc) · 2.47 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
from flask import Flask, g
from flask.ext.security import SQLAlchemyUserDatastore, current_user
from rentport.config import DebugConfig
import sys
def before_request():
g.user = current_user
def create_app(config=None):
app = Flask(__name__)
app.config.from_object(DebugConfig)
if config is not None:
app.config.from_object(config)
app.config.from_envvar('RENTPORT_CONFIG', silent=True)
with app.app_context():
import logging
logging.basicConfig(stream=sys.stdout, level=logging.INFO,
format='%(asctime)s:::%(levelname)s:::%(name)s: %(message)s')
from rentport.common.extensions import (mail, db, security,
bootstrap, kvsession, limiter)
#from .extensions import images
mail.init_app(app)
db.init_app(app)
bootstrap.init_app(app)
limiter.init_app(app)
#images.init_app(app)
def bffr():
db.create_all()
from rentport.common.model import User, Role
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
from rentport.common.forms import (RegisterForm,
ExtendedLoginForm)
security.init_app(app, user_datastore,
register_form=RegisterForm,
login_form=ExtendedLoginForm,
confirm_register_form=RegisterForm)
limiter.limit('20/minute;60/day')(app.blueprints['security'])
from redis import StrictRedis
from simplekv.memory.redisstore import RedisStore
kv_store = RedisStore(StrictRedis())
kvsession.init_app(app, kv_store)
#bind before request(s)
app.before_first_request(bffr)
app.before_request(before_request)
# NOTE: subtle path bugs with templates and routing
#
# The app object overrides the options set by the blueprint
# like, the template_folder and url_prefix
from rentport.views import (issue, relation, housing,
profile, fee, misc, provider)
app.register_blueprint(misc)
app.register_blueprint(issue)
app.register_blueprint(relation)
app.register_blueprint(housing)
app.register_blueprint(profile)
app.register_blueprint(fee)
app.register_blueprint(provider)
return app
__all__=['create_app']
if __name__ == "__main__":
os.environ['DEBUG']="1"
create_app().run(debug=True)