1
|
1 #!/usr/bin/python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 import flask
|
2
|
5 from ConfigParser import SafeConfigParser, NoSectionError
|
1
|
6 from mfrontend.views.frontend import frontend
|
|
7 from mfrontend import db, utils
|
|
8
|
|
9
|
|
10 #-- konfiguracja
|
2
|
11 config = SafeConfigParser()
|
1
|
12 while True:
|
|
13 try:
|
2
|
14 config.read('config.ini')
|
1
|
15 DATABASE = config.get('Basic', 'Database')
|
|
16 DEBUG = config.getboolean('Basic', 'Debug')
|
|
17 SECRET_KEY = config.get('Basic', 'Secret_Key')
|
|
18 break
|
2
|
19 except NoSectionError:
|
1
|
20 utils.default_ini()
|
|
21 #-- koniec konfiguracji
|
|
22
|
|
23 app = flask.Flask(__name__)
|
|
24 app.register_module(frontend)
|
|
25 app.config.from_object(__name__)
|
|
26 app.config.from_envvar('MFRONTEND_SETTINGS', silent=True)
|
|
27
|
|
28 @app.before_request
|
|
29 def before_request():
|
|
30 """Funkcja wywoływana zawsze przed wykonaniem żądania"""
|
|
31 db.connect_db()
|
|
32
|
|
33 @app.after_request
|
|
34 def after_request(response):
|
|
35 db.disconnect_db()
|
|
36 return response
|