Linked Djangos settings to pyShelfs config

This commit is contained in:
Mike Young
2019-12-22 13:35:58 -05:00
parent ee43b85cb8
commit 083f82fde1
5 changed files with 36 additions and 5 deletions

3
config.json vendored
View File

@@ -7,5 +7,6 @@
"DATABASE": "pyshelf", "DATABASE": "pyshelf",
"USER": "pyshelf", "USER": "pyshelf",
"PASSWORD": "pyshelf", "PASSWORD": "pyshelf",
"BOOKSHELF": "data/shelf.json" "BOOKSHELF": "data/shelf.json",
"ALLOWED_HOSTS": "*"
} }

8
install.py Normal file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/python
import pathlib
import sys
PRG_PATH = pathlib.Path.cwd()
LIB_PATH = pathlib.Path.joinpath(PRG_PATH, "src", "backend", "lib")
sys.path.insert(0, PRG_PATH)

2
pyproject.toml vendored
View File

@@ -7,4 +7,4 @@ use_parentheses = true
# NOTE: the known_third_party setting is managed by # NOTE: the known_third_party setting is managed by
# seed-isort-config and should not be modified directly. # seed-isort-config and should not be modified directly.
# Any changes made to this setting will be overwritten. # Any changes made to this setting will be overwritten.
known_third_party = ["bs4", "django", "interface", "psycopg2", "requests"] known_third_party = ["backend", "bs4", "django", "interface", "psycopg2", "requests"]

View File

@@ -36,6 +36,10 @@ class Config:
self.root = root self.root = root
self.auto_scan = True self.auto_scan = True
self.allowed_hosts = _data["ALLOWED_HOSTS"]
self.db_user = _data["USER"]
self.db_pass = _data["PASSWORD"]
def open_file(self, _cp): def open_file(self, _cp):
""" """
Opens config.json and reads in configuration options Opens config.json and reads in configuration options

View File

@@ -11,7 +11,17 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
""" """
import os import os
import sys
from pathlib import Path
from backend.lib.config import Config
CUR_DIR = Path.cwd()
PRG_DIR = CUR_DIR.parts[0:-1]
PRG_DIR = Path(*PRG_DIR)
CONFIG = Config(PRG_DIR)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -23,9 +33,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = "@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18" SECRET_KEY = "@(9b9jslgg41u1u=mr)-2*-n2x0vef0zsy39*z@sz18&tvow18"
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False DEBUG = True
ALLOWED_HOSTS = ["*"] ALLOWED_HOSTS = CONFIG.allowed_hosts
# Application definition # Application definition
@@ -82,7 +92,7 @@ WSGI_APPLICATION = "frontend.wsgi.application"
# Database # Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
"""
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.postgresql", "ENGINE": "django.db.backends.postgresql",
@@ -92,7 +102,15 @@ DATABASES = {
# "NAME": os.path.join(BASE_DIR, "db.sqlite3"), # "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
} }
} }
"""
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": CONFIG.user,
"PASSWORD": CONFIG.password,
}
}
# Password validation # Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators