diff --git a/config.json b/config.json index 77f2b02..7940a68 100644 --- a/config.json +++ b/config.json @@ -7,5 +7,6 @@ "DATABASE": "pyshelf", "USER": "pyshelf", "PASSWORD": "pyshelf", - "BOOKSHELF": "data/shelf.json" + "BOOKSHELF": "data/shelf.json", + "ALLOWED_HOSTS": "*" } diff --git a/install.py b/install.py new file mode 100644 index 0000000..04bdeb3 --- /dev/null +++ b/install.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 38d47ab..2db2a64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,4 +7,4 @@ use_parentheses = true # NOTE: the known_third_party setting is managed by # seed-isort-config and should not be modified directly. # 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"] diff --git a/src/backend/lib/config.py b/src/backend/lib/config.py index 1591db6..a78054d 100755 --- a/src/backend/lib/config.py +++ b/src/backend/lib/config.py @@ -36,6 +36,10 @@ class Config: self.root = root 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): """ Opens config.json and reads in configuration options diff --git a/src/frontend/settings.py b/src/frontend/settings.py index 397f10e..c669448 100755 --- a/src/frontend/settings.py +++ b/src/frontend/settings.py @@ -11,7 +11,17 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ """ 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, ...) 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" # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True -ALLOWED_HOSTS = ["*"] +ALLOWED_HOSTS = CONFIG.allowed_hosts # Application definition @@ -82,7 +92,7 @@ WSGI_APPLICATION = "frontend.wsgi.application" # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases - +""" DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", @@ -92,7 +102,15 @@ DATABASES = { # "NAME": os.path.join(BASE_DIR, "db.sqlite3"), } } +""" +DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": CONFIG.user, + "PASSWORD": CONFIG.password, + } +} # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators