summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-11-25 22:09:22 +0100
committeremkael <emkael@tlen.pl>2016-11-25 22:10:37 +0100
commit542e7cfbf6c543a234309feb42d087779a7cdc12 (patch)
tree067e79e0631f0fffa4928000069cea65cd617a1a
parent28ce1bfbff9a738b33409df0e575985f6f1b3ce2 (diff)
Configuration from external JSON file. Fixes #2
-rw-r--r--.gitignore1
-rwxr-xr-xql/settings.py37
2 files changed, 30 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 0903698..38e438d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ __pycache__
/venv*
build
dist
+config.json
diff --git a/ql/settings.py b/ql/settings.py
index a975f14..df68ae3 100755
--- a/ql/settings.py
+++ b/ql/settings.py
@@ -1,12 +1,33 @@
+import json, sys
+
+def _fetch_settings(config_path, constant_config, default_config):
+ try:
+ config = constant_config.copy()
+ config.update(json.load(open(config_path)))
+ return config
+ except FileNotFoundError:
+ with open(config_path, 'w') as new_config:
+ json.dump(default_config, new_config)
+ print('Config file created, fill it up!')
+ sys.exit()
+ except ValueError:
+ print('Config file invalid, fix it!')
+ sys.exit(1)
+
DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'HOST': '127.0.0.1',
- 'PORT': '3306',
- 'USER': 'your-username',
- 'PASSWORD': 'your-password',
- 'NAME': 'your-database-name',
- }
+ 'default': _fetch_settings(
+ 'config.json',
+ {
+ 'ENGINE': 'mysql.connector.django'
+ },
+ {
+ 'HOST': 'localhost',
+ 'PORT': '3306',
+ 'USER': 'root',
+ 'PASSWORD': '',
+ 'NAME': 'belongs_to_us'
+ }
+ )
}
INSTALLED_APPS = (