diff --git a/.gitignore b/.gitignore index a97ea05..6bbfcec 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ elm-stuff static/jon.js __pycache__ *.swp +py/jon/config.json diff --git a/py/jon/__init__.py b/py/jon/__init__.py index 9281ec4..b9d8bae 100644 --- a/py/jon/__init__.py +++ b/py/jon/__init__.py @@ -1,4 +1,5 @@ import inspect +import json from flask import Flask, render_template @@ -7,9 +8,10 @@ from . import db, inventory, location, template_utils def create_app(): app = Flask(__name__) - app.config.from_mapping( - SECRET_KEY="dev" - ) + app.config.from_file("default-config.json", load=json.load) + # You don't need a config.json. If you don't provide one, default-config.json + # is used. + app.config.from_file("config.json", load=json.load, silent=True) db.init_app(app) diff --git a/py/jon/db/__init__.py b/py/jon/db/__init__.py index b56e274..4a3a945 100644 --- a/py/jon/db/__init__.py +++ b/py/jon/db/__init__.py @@ -1,6 +1,6 @@ import psycopg2 -from flask import g +from flask import current_app, g from pathlib import Path from psycopg2.extras import RealDictCursor @@ -9,7 +9,7 @@ def get_db(): if "db" not in g: # TODO: Make this configurable and use a default that works # on the pool computers. - g.db = psycopg2.connect("host=localhost dbname=garfield") + g.db = psycopg2.connect(current_app.config["DB_CONNECTION_STRING"]) run_query_on(g.db, "add_views.sql", None) return g.db diff --git a/py/jon/default-config.json b/py/jon/default-config.json new file mode 100644 index 0000000..56511d3 --- /dev/null +++ b/py/jon/default-config.json @@ -0,0 +1,4 @@ +{ + "SECRET_KEY": "dev", + "DB_CONNECTION_STRING": "host=fsmi-db dbname=garfield" +} diff --git a/py/jon/templates/base.html b/py/jon/templates/base.html index 735b1f4..a603e1e 100644 --- a/py/jon/templates/base.html +++ b/py/jon/templates/base.html @@ -83,6 +83,13 @@ + {% if config.DEBUG %} + + config + {% for key, value in config.items() %}{{ key }} = {{ value }} +{% endfor %} + + {% endif %}
config
{% for key, value in config.items() %}{{ key }} = {{ value }} +{% endfor %}