From 456fb25596da750e4f5833b85ca47af8365bc304 Mon Sep 17 00:00:00 2001 From: Tomasz Knapik Date: Tue, 12 Nov 2024 17:09:51 +0000 Subject: [PATCH] Install dj-database-url --- .isort.cfg | 6 ++++++ config/jinja2.py | 1 + config/settings/base.py | 14 ++++---------- docker-compose.yml | 6 +----- poetry.lock | 30 ++++++++++++++++++++++++++++-- pyproject.toml | 1 + 6 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..3f1129d --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,6 @@ +[settings] +profile=black +sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER +known_first_party=config +known_django=django +default_section=THIRDPARTY diff --git a/config/jinja2.py b/config/jinja2.py index ba8f36d..9a7f66f 100644 --- a/config/jinja2.py +++ b/config/jinja2.py @@ -5,6 +5,7 @@ from django.conf import settings from django.templatetags.static import static from django.urls import reverse + from jinja2 import Environment diff --git a/config/settings/base.py b/config/settings/base.py index 648a39c..793159c 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -3,6 +3,8 @@ from pathlib import Path from sysconfig import get_path +import dj_database_url + from config.util import strtobool PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -69,16 +71,8 @@ # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases -DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": os.environ.get("DATABASE_NAME", ""), - "USER": os.environ.get("DATABASE_USER", ""), - "PASSWORD": os.environ.get("DATABASE_PASSWORD", ""), - "HOST": os.environ.get("DATABASE_HOST", ""), - "PORT": os.environ.get("DATABASE_PORT", "5432"), - } -} +DATABASES = {"default": dj_database_url.config(conn_max_age=600)} + # Password validation # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators diff --git a/docker-compose.yml b/docker-compose.yml index 6ac7e21..84db35c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,11 +10,7 @@ services: - DJANGO_SETTINGS_MODULE=config.settings.develop - SECRET_KEY=abc123 - NPM_DEVELOP_COMMAND=dev - - DATABASE_NAME=postgres - - DATABASE_USER=postgres - - DATABASE_PASSWORD=postgres - - DATABASE_HOST=db - - DATABASE_PORT=5432 + - DATABASE_URL=postgres://postgres:postgres@db:5432/postgres - DJANGO_SUPERUSER_PASSWORD=admin - DJANGO_SUPERUSER_USERNAME=admin - COOKIE_DOMAIN=localhost diff --git a/poetry.lock b/poetry.lock index 27963e0..eefa0f3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "asgiref" @@ -175,6 +175,21 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "dj-database-url" +version = "2.3.0" +description = "Use Database URLs in your Django Application." +optional = false +python-versions = "*" +files = [ + {file = "dj_database_url-2.3.0-py3-none-any.whl", hash = "sha256:bb0d414ba0ac5cd62773ec7f86f8cc378a9dbb00a80884c2fc08cc570452521e"}, + {file = "dj_database_url-2.3.0.tar.gz", hash = "sha256:ae52e8e634186b57e5a45e445da5dc407a819c2ceed8a53d1fac004cc5288787"}, +] + +[package.dependencies] +Django = ">=4.2" +typing_extensions = ">=3.10.0.0" + [[package]] name = "django" version = "5.1.3" @@ -547,6 +562,17 @@ files = [ [package.dependencies] flask = ">=2" +[[package]] +name = "typing-extensions" +version = "4.12.2" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = false +python-versions = ">=3.8" +files = [ + {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, + {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, +] + [[package]] name = "tzdata" version = "2024.2" @@ -609,4 +635,4 @@ brotli = ["brotli"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "3d1f74893baf9828a54fd62027b1a21905804062388dd1adc847762b2a04505c" +content-hash = "1e775d099894291b1ecc41bb74ae73b89aab7c934b795b02132dc7b2d8013218" diff --git a/pyproject.toml b/pyproject.toml index e6eb205..7b7c2ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ django = "^5.0.7" psycopg2-binary = "^2.9.9" django-csp = "^3.8" whitenoise = "^6.7.0" +dj-database-url = "^2.3.0" [tool.poetry.group.dev] optional = true