Add configuration files

This commit is contained in:
BuildTools 2023-06-30 17:37:09 +02:00
parent 0f3416b49a
commit 38c827d0d8
5 changed files with 19 additions and 5 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ elm-stuff
static/jon.js
__pycache__
*.swp
py/jon/config.json

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,4 @@
{
"SECRET_KEY": "dev",
"DB_CONNECTION_STRING": "host=fsmi-db dbname=garfield"
}

View File

@ -83,6 +83,13 @@
</ul>
</nav>
{% if config.DEBUG %}
<details>
<summary><code>config</code></summary>
<pre>{% for key, value in config.items() %}{{ key }} = {{ value }}
{% endfor %}</pre>
</details>
{% endif %}
</header>
<main>