Add configuration files
This commit is contained in:
parent
0f3416b49a
commit
38c827d0d8
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ elm-stuff
|
|||||||
static/jon.js
|
static/jon.js
|
||||||
__pycache__
|
__pycache__
|
||||||
*.swp
|
*.swp
|
||||||
|
py/jon/config.json
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import inspect
|
import inspect
|
||||||
|
import json
|
||||||
|
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
|
|
||||||
@ -7,9 +8,10 @@ from . import db, inventory, location, template_utils
|
|||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_mapping(
|
app.config.from_file("default-config.json", load=json.load)
|
||||||
SECRET_KEY="dev"
|
# 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)
|
db.init_app(app)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
from flask import g
|
from flask import current_app, g
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from psycopg2.extras import RealDictCursor
|
from psycopg2.extras import RealDictCursor
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ def get_db():
|
|||||||
if "db" not in g:
|
if "db" not in g:
|
||||||
# TODO: Make this configurable and use a default that works
|
# TODO: Make this configurable and use a default that works
|
||||||
# on the pool computers.
|
# 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)
|
run_query_on(g.db, "add_views.sql", None)
|
||||||
|
|
||||||
return g.db
|
return g.db
|
||||||
|
4
py/jon/default-config.json
Normal file
4
py/jon/default-config.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"SECRET_KEY": "dev",
|
||||||
|
"DB_CONNECTION_STRING": "host=fsmi-db dbname=garfield"
|
||||||
|
}
|
@ -83,6 +83,13 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
{% if config.DEBUG %}
|
||||||
|
<details>
|
||||||
|
<summary><code>config</code></summary>
|
||||||
|
<pre>{% for key, value in config.items() %}{{ key }} = {{ value }}
|
||||||
|
{% endfor %}</pre>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user