Skip to content

Commit

Permalink
More settings tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
danniel committed May 24, 2024
1 parent 17fc7ad commit cb82224
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 26 additions & 11 deletions backend/civil_society_vote/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@
"""

import os
from copy import deepcopy
from pathlib import Path

import environ
import sentry_sdk
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"]

Expand Down Expand Up @@ -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"),
Expand All @@ -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
Expand All @@ -90,7 +101,13 @@
DEFAULT_FROM_EMAIL=(str, "[email protected]"),
NO_REPLY_EMAIL=(str, "[email protected]"),
)
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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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/"


Expand Down
3 changes: 0 additions & 3 deletions backend/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion backend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docker/dockerfiles/Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PYTHON_VERSION=3.11.8
ARG PYTHON_VERSION=3.11.9

FROM python:${PYTHON_VERSION}-slim-bookworm as build

Expand Down

0 comments on commit cb82224

Please sign in to comment.