From cb822245bde076b2cee93eb82606b485a68ec8bb Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Fri, 24 May 2024 08:18:24 +0300 Subject: [PATCH] More settings tweaks --- .gitignore | 7 +++-- backend/civil_society_vote/settings.py | 37 ++++++++++++++++++-------- backend/hub/models.py | 3 --- backend/manage.py | 2 +- docker/dockerfiles/Dockerfile.backend | 2 +- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 7b7555a2..e14e56f9 100644 --- a/.gitignore +++ b/.gitignore @@ -143,7 +143,6 @@ dmypy.json # Cython debug symbols cython_debug/ -# static files generated from Django application using `collectstatic` -media -mediafiles -staticfiles +# ignore the static files destination directory +backend/static +backend/media diff --git a/backend/civil_society_vote/settings.py b/backend/civil_society_vote/settings.py index e219e875..33b67052 100644 --- a/backend/civil_society_vote/settings.py +++ b/backend/civil_society_vote/settings.py @@ -9,6 +9,7 @@ """ import os +from copy import deepcopy from pathlib import Path import environ @@ -16,10 +17,19 @@ from django.urls import reverse_lazy # noqa +# Constants for memory sizes +KIBIBYTE = 1024 +MEBIBYTE = KIBIBYTE * 1024 +GIBIBYTE = MEBIBYTE * 1024 +TEBIBYTE = GIBIBYTE * 1024 + + +# Environment parameters +root = Path(__file__).resolve().parent.parent.parent + # Build paths inside the project like this: BASE_DIR / 'subdir'. -# ROOT = Path(__file__).resolve().parent.parent.parent # TODO: For when we'll use one settings.py -ROOT = Path(__file__).resolve().parent.parent.parent.parent -BASE_DIR = os.path.abspath(os.path.join(ROOT, "backend")) +BASE_DIR = os.path.abspath(os.path.join(root, "backend")) + SILENCED_SYSTEM_CHECKS = ["ckeditor.W001"] @@ -51,12 +61,14 @@ ENABLE_DEBUG_TOOLBAR=(bool, False), ENVIRONMENT=(str, "production"), SECRET_KEY=(str, "replace-with-a-secret-key"), - LOG_LEVEL=(str, "INFO"), + LOGLEVEL=(str, "INFO"), ALLOWED_HOSTS=(list, ["*"]), IS_CONTAINERIZED=(bool, False), LANGUAGE_CODE=(str, "ro"), TIME_ZONE=(str, "Europe/Bucharest"), AUDITLOG_EXPIRY_DAYS=(int, 45), + DATA_UPLOAD_MAX_MEMORY_SIZE=(int, 3 * MEBIBYTE), + MAX_DOCUMENT_SIZE=(int, 2 * MEBIBYTE), # db settings # DATABASE_ENGINE=(str, "sqlite3"), DATABASE_NAME=(str, "default"), @@ -75,7 +87,6 @@ RECAPTCHA_PRIVATE_KEY=(str, ""), # TODO Settings Cleanup: - USE_S3=(bool, False), ANALYTICS_ENABLED=(bool, False), GLOBAL_SUPPORT_ENABLED=(bool, False), # email settings @@ -90,7 +101,13 @@ DEFAULT_FROM_EMAIL=(str, "no-reply@code4.ro"), NO_REPLY_EMAIL=(str, "no-reply@code4.ro"), ) -environ.Env.read_env(f"{ROOT}/.env") # reading .env file + +# reading .env file +dot_env_path = os.path.abspath(os.path.join(root, ".env")) +environ.Env.read_env(dot_env_path) + +# SECURITY WARNING: keep the secret key used in production secret +SECRET_KEY = env("SECRET_KEY") DEBUG = env("DEBUG") ENVIRONMENT = env.str("ENVIRONMENT") @@ -367,9 +384,8 @@ def show_toolbar(request): } if IS_CONTAINERIZED: - # Where ViteJS assets are built - STATIC_ROOT = os.path.abspath(os.path.join(os.sep, "var", "www", "factory", "backend", "static")) - MEDIA_ROOT = os.path.abspath(os.path.join(os.sep, "var", "www", "factory", "backend", "media")) + STATIC_ROOT = os.path.abspath(os.path.join(os.sep, "var", "www", "votong", "backend", "static")) + MEDIA_ROOT = os.path.abspath(os.path.join(os.sep, "var", "www", "votong", "backend", "media")) # Maximum request size excludind the uploaded files DATA_UPLOAD_MAX_MEMORY_SIZE = env.int("DATA_UPLOAD_MAX_MEMORY_SIZE") @@ -403,8 +419,7 @@ def show_toolbar(request): MEDIA_URL = "/media/" MEDIA_ROOT = os.path.abspath(os.path.join(BASE_DIR, "mediafiles")) -STATICFILES_DIRS = [] # TODO? (os.path.abspath(os.path.join(BASE_DIR, "static")),) -STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, "staticfiles")) +STATICFILES_DIRS = (os.path.abspath(os.path.join(BASE_DIR, "static_extras")),) STATIC_URL = "/static/" diff --git a/backend/hub/models.py b/backend/hub/models.py index b0eb07ec..92fc4864 100644 --- a/backend/hub/models.py +++ b/backend/hub/models.py @@ -32,9 +32,6 @@ def select_public_storage(): return storages["public"] -PrivateMediaStorageClass = get_storage_class(settings.PRIVATE_FILE_STORAGE) -PublicMediaStorageClass = get_storage_class(settings.DEFAULT_FILE_STORAGE) - COUNTY_RESIDENCE = [ ("Alba", "Alba Iulia"), diff --git a/backend/manage.py b/backend/manage.py index 4966091d..8aae6103 100755 --- a/backend/manage.py +++ b/backend/manage.py @@ -4,7 +4,7 @@ def main(): - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "civil_society_vote.settings.dev") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "civil_society_vote.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/docker/dockerfiles/Dockerfile.backend b/docker/dockerfiles/Dockerfile.backend index e069b5ee..4d0a40a4 100644 --- a/docker/dockerfiles/Dockerfile.backend +++ b/docker/dockerfiles/Dockerfile.backend @@ -1,4 +1,4 @@ -ARG PYTHON_VERSION=3.11.8 +ARG PYTHON_VERSION=3.11.9 FROM python:${PYTHON_VERSION}-slim-bookworm as build