Changeset - cce68b00e8fe
[Not reviewed]
version_5
0 1 1
Dennis Fink - 10 years ago 2015-08-25 17:48:45
dennis.fink@c3l.lu
Move default config in own module
2 files changed with 25 insertions and 2 deletions:
0 comments (0 inline, 0 general)
ennstatus/__init__.py
Show inline comments
 
@@ -18,12 +18,15 @@ config_file = os.path.abspath('config.js
 

	
 

	
 
def create_app():
 

	
 
    app = Flask(__name__)
 

	
 
    import ennstatus.config as config
 
    config.init_app(app)
 

	
 
    if not hasattr(app.config, 'from_json'):
 
        def from_json(file, silent=True):
 
            try:
 
                with open(file, encoding='utf-8') as json_file:
 
                    obj = json.load(json_file)
 
            except IOError:
 
@@ -37,14 +40,12 @@ def create_app():
 

	
 
            return True
 

	
 
        app.config.from_json = from_json
 

	
 
    app.config.from_json(config_file)
 
    app.config.setdefault('ENNSTATUS_MOMENTJS_FORMAT', 'DD MMMM YYYY HH:mm:ss')
 
    app.config.setdefault('ENNSTATUS_STRFTIME_FORMAT', '%d %B %Y %H:%M:%S')
 

	
 
    app.wsgi_app = ProxyFix(app.wsgi_app)
 

	
 
    bootstrap.init_app(app)
 
    csrf.init_app(app)
 
    moment.init_app(app)
ennstatus/config.py
Show inline comments
 
new file 100644
 
import os
 
import base64
 

	
 

	
 
def init_app(app):
 

	
 
    config = app.config
 

	
 
    _default_secret_key = base64.b64encode(os.urandom(32)).decode('utf-8')
 

	
 
    config['SECRET_KEY'] = os.environ.get('SECRET_KEY', _default_secret_key)
 

	
 
    # Flask-Bootstrap
 
    config.setdefault('BOOTSTRAP_SERVE_LOCAL', True)
 

	
 
    # ennstatus
 

	
 
    # moment.js string formatting
 
    # http://momentjs.com/docs/#/displaying/format/
 
    config.setdefault('ENNSTATUS_MOMENTJS_FORMAT', 'DD MMMM YYYY HH:mm:ss')
 

	
 
    config.setdefault('ENNSTATUS_STRFTIME_FORMAT', '%d %B %Y %H:%M:%S')
0 comments (0 inline, 0 general)