diff --git a/freedoi/settings.py b/freedoi/settings.py index 68acd40..cf259d9 100644 --- a/freedoi/settings.py +++ b/freedoi/settings.py @@ -5,10 +5,10 @@ from autosecretkey import AutoSecretKey # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent -ask = AutoSecretKey("settings.ini", template=BASE_DIR / "settings.ini.template") +ASK = AutoSecretKey("settings.ini", template=BASE_DIR / "settings.ini.template") -SECRET_KEY = ask.secret_key -CONFIG = ask.config +SECRET_KEY = ASK.secret_key +CONFIG = ASK.config DEBUG = CONFIG.getboolean("FreeDOI", "debug", fallback=False) ALLOWED_HOSTS = CONFIG.get("FreeDOI", "host", fallback="*").split(",") @@ -69,12 +69,37 @@ WSGI_APPLICATION = "freedoi.wsgi.application" # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": "db.sqlite3", +if (dbtype := "MySQL") in ASK.config or (dbtype := "MariaDB") in ASK.config: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": ASK.config.get(dbtype, "Database"), + "USER": ASK.config.get(dbtype, "Username"), + "PASSWORD": ASK.config.get(dbtype, "Password"), + "HOST": ASK.config.get(dbtype, "Host", fallback="localhost"), + "PORT": ASK.config.getint(dbtype, "Port", fallback=3306), + } + } + +elif (dbtype := "Postgres") in ASK.config or (dbtype := "PostgreSQL") in ASK.config: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": ASK.config.get(dbtype, "Database"), + "USER": ASK.config.get(dbtype, "Username"), + "PASSWORD": ASK.config.get(dbtype, "Password"), + "HOST": ASK.config.get(dbtype, "Host", fallback="localhost"), + "PORT": ASK.config.getint(dbtype, "Port", fallback=5432), + } + } + +else: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "db.sqlite3", + } } -} # Password validation