mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Introduce config file for application
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -63,3 +63,4 @@ assets/stylesheets/govuk_template/.sass-cache/
|
||||
cache/
|
||||
static/stylesheets/govuk-template*
|
||||
static/css*
|
||||
static/css_all.css
|
||||
10
app.py
10
app.py
@@ -1,25 +1,17 @@
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
from flask.ext import assets
|
||||
from flask.ext.script import Manager, Server
|
||||
from webassets.filter import get_filter
|
||||
from app import create_app
|
||||
|
||||
|
||||
application = create_app()
|
||||
application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'development')
|
||||
manager = Manager(application)
|
||||
port = int(os.environ.get('PORT', 6012))
|
||||
manager.add_command("runserver", Server(host='0.0.0.0', port=port))
|
||||
|
||||
# debug mode - switch to False for production
|
||||
application.config['ASSETS_DEBUG'] = True
|
||||
application.config['DEBUG'] = True
|
||||
env = assets.Environment(application)
|
||||
|
||||
# debug mode - switch to True for production
|
||||
env.config['cache'] = False
|
||||
env.config['manifest'] = False
|
||||
|
||||
# Tell flask-assets where to look for our sass files.
|
||||
env.load_path = [
|
||||
os.path.join(os.path.dirname(__file__), 'app/assets/stylesheets'),
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
import os
|
||||
from flask import Flask
|
||||
from config import configs
|
||||
from flask._compat import string_types
|
||||
|
||||
|
||||
def create_app():
|
||||
def create_app(config_name):
|
||||
application = Flask(__name__)
|
||||
|
||||
# application.config['NOTIFY_API_ENVIRONMENT'] = config_name
|
||||
# application.config.from_object(configs[config_name])
|
||||
application.config['NOTIFY_API_ENVIRONMENT'] = config_name
|
||||
application.config.from_object(configs[config_name])
|
||||
init_app(application)
|
||||
|
||||
from app.main import main as main_blueprint
|
||||
application.register_blueprint(main_blueprint)
|
||||
|
||||
return application
|
||||
|
||||
|
||||
def init_app(app):
|
||||
for key, value in app.config.items():
|
||||
if key in os.environ:
|
||||
app.config[key] = convert_to_boolean(os.environ[key])
|
||||
|
||||
|
||||
def convert_to_boolean(value):
|
||||
if isinstance(value, string_types):
|
||||
if value.lower() in ['t', 'true', 'on', 'yes', '1']:
|
||||
return True
|
||||
elif value.lower() in ['f', 'false', 'off', 'no', '0']:
|
||||
return False
|
||||
|
||||
return value
|
||||
|
||||
@@ -8,11 +8,6 @@ def index():
|
||||
return 'Hello from notifications-admin'
|
||||
|
||||
|
||||
@main.route("/")
|
||||
def idx():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@main.route("/govuk")
|
||||
def govuk():
|
||||
return render_template('govuk_template.html')
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
{% assets "css_all" %}
|
||||
<style type="text/css" src="{{ ASSET_URL }}"></style>
|
||||
{% endassets %}
|
||||
</head>
|
||||
<body>
|
||||
<h1>hi</h1>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user