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
 
@@ -12,45 +12,46 @@ import gnupg
 

	
 
bootstrap = Bootstrap()
 
csrf = CsrfProtect()
 
moment = Moment()
 

	
 
config_file = os.path.abspath('config.json')
 

	
 

	
 
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:
 
                if silent:
 
                    return False
 
                raise
 

	
 
            for key in obj:
 
                if key.isupper():
 
                    app.config[key] = obj[key]
 

	
 
            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)
 

	
 
    from .status.functions import mail
 
    mail.init_app(app)
 

	
 
    from .root.views import root_page
 
    app.register_blueprint(root_page)
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)