/
main.py
executable file
·72 lines (52 loc) · 1.48 KB
/
main.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
#!/usr/bin/env python2
# -*- encoding: utf-8 -*-
"""
Glues everything together and launches the app
"""
import os
import yaml
from flask import Flask
from models import db
from login import login_manager, inject_roles
import views
from lib import upload, filters, mail
CONFIG_FILE = 'config.yaml'
def load_config(app):
# take config from file
with open(CONFIG_FILE) as f:
config = yaml.load(f)
# load email templates
templates = config['MAIL_TEMPLATES']
config_mails = dict()
for f in os.listdir(templates):
name = os.path.splitext(f)[0].upper()
# load template content in config
with open(os.path.join(templates, f), 'rb') as f_handle:
config_mails[name] = f_handle.read()
config['MAIL'] = config_mails
app.config.update(config)
def create_app():
app = Flask(__name__)
load_config(app)
app.debug = app.config['DEBUG']
app.secret_key = app.config['SECRET_KEY']
# init flask extensions
db.init_app(app)
mail.init_app(app)
login_manager.init_app(app)
app.context_processor(inject_roles)
# init my modules
upload.init_app(app)
filters.init_app(app)
views.init_app(app)
# register routes
app.register_blueprint(views.bp_basic)
app.register_blueprint(views.bp_responsable)
app.register_blueprint(views.bp_activite)
app.register_blueprint(views.bp_brn)
return app
def main():
app = create_app()
app.run()
if __name__ == '__main__':
main()