summaryrefslogtreecommitdiffstats
path: root/takahe/settings
diff options
context:
space:
mode:
Diffstat (limited to 'takahe/settings')
-rw-r--r--takahe/settings/__init__.py0
-rw-r--r--takahe/settings/base.py107
-rw-r--r--takahe/settings/development.py13
-rw-r--r--takahe/settings/production.py17
-rw-r--r--takahe/settings/testing.py4
5 files changed, 141 insertions, 0 deletions
diff --git a/takahe/settings/__init__.py b/takahe/settings/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/takahe/settings/__init__.py
diff --git a/takahe/settings/base.py b/takahe/settings/base.py
new file mode 100644
index 0000000..a2ccb98
--- /dev/null
+++ b/takahe/settings/base.py
@@ -0,0 +1,107 @@
+import os
+from pathlib import Path
+
+BASE_DIR = Path(__file__).resolve().parent.parent.parent
+
+# Application definition
+
+INSTALLED_APPS = [
+ "django.contrib.admin",
+ "django.contrib.auth",
+ "django.contrib.contenttypes",
+ "django.contrib.sessions",
+ "django.contrib.messages",
+ "django.contrib.staticfiles",
+ "crispy_forms",
+ "core",
+ "activities",
+ "users",
+ "stator",
+]
+
+MIDDLEWARE = [
+ "django.middleware.security.SecurityMiddleware",
+ "django.contrib.sessions.middleware.SessionMiddleware",
+ "django.middleware.common.CommonMiddleware",
+ "django.middleware.csrf.CsrfViewMiddleware",
+ "django.contrib.auth.middleware.AuthenticationMiddleware",
+ "django.contrib.messages.middleware.MessageMiddleware",
+ "django.middleware.clickjacking.XFrameOptionsMiddleware",
+ "users.middleware.IdentityMiddleware",
+]
+
+ROOT_URLCONF = "takahe.urls"
+
+TEMPLATES = [
+ {
+ "BACKEND": "django.template.backends.django.DjangoTemplates",
+ "DIRS": [BASE_DIR / "templates"],
+ "APP_DIRS": True,
+ "OPTIONS": {
+ "context_processors": [
+ "django.template.context_processors.debug",
+ "django.template.context_processors.request",
+ "django.contrib.auth.context_processors.auth",
+ "django.contrib.messages.context_processors.messages",
+ "core.context.config_context",
+ ],
+ },
+ },
+]
+
+WSGI_APPLICATION = "takahe.wsgi.application"
+
+DATABASES = {
+ "default": {
+ "ENGINE": "django.db.backends.postgresql_psycopg2",
+ "HOST": os.environ.get("POSTGRES_HOST", "localhost"),
+ "NAME": os.environ.get("POSTGRES_DB", "takahe"),
+ "USER": os.environ.get("POSTGRES_USER", "postgres"),
+ "PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
+ }
+}
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
+ },
+ {
+ "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
+ },
+ {
+ "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
+ },
+ {
+ "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
+ },
+]
+
+LANGUAGE_CODE = "en-us"
+
+TIME_ZONE = "UTC"
+
+USE_I18N = True
+
+USE_TZ = True
+
+STATIC_URL = "static/"
+
+DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
+
+AUTH_USER_MODEL = "users.User"
+
+LOGIN_URL = "/auth/login/"
+LOGOUT_URL = "/auth/logout/"
+LOGIN_REDIRECT_URL = "/"
+LOGOUT_REDIRECT_URL = "/"
+
+STATICFILES_FINDERS = [
+ "django.contrib.staticfiles.finders.FileSystemFinder",
+ "django.contrib.staticfiles.finders.AppDirectoriesFinder",
+]
+
+STATICFILES_DIRS = [
+ BASE_DIR / "static",
+]
+
+ALLOWED_HOSTS = ["*"]
diff --git a/takahe/settings/development.py b/takahe/settings/development.py
new file mode 100644
index 0000000..4e0098b
--- /dev/null
+++ b/takahe/settings/development.py
@@ -0,0 +1,13 @@
+import os
+
+from .base import * # noqa
+
+# Load secret key from environment with a fallback
+SECRET_KEY = os.environ.get("TAKAHE_SECRET_KEY", "insecure_secret")
+
+# Disable the CRSF origin protection
+MIDDLEWARE.insert(0, "core.middleware.AlwaysSecureMiddleware")
+
+# Ensure debug features are on
+DEBUG = True
+CRISPY_FAIL_SILENTLY = False
diff --git a/takahe/settings/production.py b/takahe/settings/production.py
new file mode 100644
index 0000000..2f943f4
--- /dev/null
+++ b/takahe/settings/production.py
@@ -0,0 +1,17 @@
+import os
+
+from .base import * # noqa
+
+# Load secret key from environment
+try:
+ SECRET_KEY = os.environ["TAKAHE_SECRET_KEY"]
+except KeyError:
+ print("You must specify the TAKAHE_SECRET_KEY environment variable!")
+ os._exit(1)
+
+# Ensure debug features are off
+DEBUG = False
+CRISPY_FAIL_SILENTLY = True
+
+# TODO: Allow better setting of allowed_hosts, if we need to
+ALLOWED_HOSTS = ["*"]
diff --git a/takahe/settings/testing.py b/takahe/settings/testing.py
new file mode 100644
index 0000000..6527333
--- /dev/null
+++ b/takahe/settings/testing.py
@@ -0,0 +1,4 @@
+from .base import * # noqa
+
+# Fixed secret key
+SECRET_KEY = "testing_secret"