From 4811fbeadae754748d4988732cde792e28f7b89e Mon Sep 17 00:00:00 2001 From: sinavir Date: Mon, 6 Mar 2023 11:53:25 +0100 Subject: [PATCH] add settings for prod, debug toolbar --- hackens_orga/hackens_orga/settings.py | 35 +++++++++++++++++++++++---- hackens_orga/hackens_orga/urls.py | 1 + shell.nix | 1 + 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/hackens_orga/hackens_orga/settings.py b/hackens_orga/hackens_orga/settings.py index e0c7b7f..3869c1f 100644 --- a/hackens_orga/hackens_orga/settings.py +++ b/hackens_orga/hackens_orga/settings.py @@ -10,8 +10,11 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ +import os from pathlib import Path +env_prefix = "HACKENS_ORGA_" + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,12 +23,21 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-d4qh9v-en$&f%$j$jyhqkn_th#ow-e22bs^stx(n33sg-eyfhd" +SECRET_KEY = os.environ.get( + f"{env_prefix}SECRET_KEY", + "django-insecure-d4qh9v-en$&f%$j$jyhqkn_th#ow-e22bs^stx(n33sg-eyfhd", +) # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.environ.get(f"{env_prefix}DEBUG", "1") != "0" -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = os.environ.get( + f"{env_prefix}ALLOWED_HOSTS", "127.0.0.1,localhost" +).split(",") + +INTERNAL_IPS = [ + "127.0.0.1", +] # Application definition @@ -46,6 +58,7 @@ INSTALLED_APPS = [ "shared", ] + MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", @@ -56,6 +69,14 @@ MIDDLEWARE = [ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] +if DEBUG: + INSTALLED_APPS += [ + "debug_toolbar", + ] + MIDDLEWARE = [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + ] + MIDDLEWARE + ROOT_URLCONF = "hackens_orga.urls" TEMPLATES = [ @@ -83,6 +104,9 @@ AUTHENTICATION_BACKENDS = [ "authens.backends.ENSCASBackend", ] +AUTHENS_ALLOW_STAFF = True +AUTHENS_USE_OLDCAS = False + from django.urls import reverse_lazy LOGIN_URL = reverse_lazy("authens:login") @@ -90,7 +114,6 @@ LOGIN_URL = reverse_lazy("authens:login") LOGOUT_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/" -AUTHENS_USE_OLDCAS = False # Django-rest-framework # https://www.django-rest-framework.org/ @@ -106,10 +129,12 @@ REST_FRAMEWORK = { # Database # https://docs.djangoproject.com/en/3.2/ref/settings/#databases +DB_FILE = os.environ.get(f"{env_prefix}DB_FILE", BASE_DIR / "db.sqlite3") + DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + "NAME": DB_FILE, } } diff --git a/hackens_orga/hackens_orga/urls.py b/hackens_orga/hackens_orga/urls.py index ad765c4..d08ac1f 100644 --- a/hackens_orga/hackens_orga/urls.py +++ b/hackens_orga/hackens_orga/urls.py @@ -23,5 +23,6 @@ urlpatterns = [ path("api/budget/", include("budget.urls")), path("api/agent/", include("agent.urls")), # path("api/wishlist/", include("wishlist.urls")), + path('__debug__/', include('debug_toolbar.urls')), path("", include("frontend.urls")), ] diff --git a/shell.nix b/shell.nix index 94ec200..f6297e6 100644 --- a/shell.nix +++ b/shell.nix @@ -15,6 +15,7 @@ pkgs.mkShell { ps.black ps.isort ps.djangorestframework + ps.django-debug-toolbar ps.authens # (ps.django-extensions.override { inherit django; }) # ps.django-compressor