Files
outbo-2-stgclone/evg-outbo-api/outbo/settings.py
T
2024-11-27 13:18:16 +01:00

240 lines
7.8 KiB
Python
Executable File

import os
from configurations import Configuration, values
class Base(Configuration):
@classmethod
def pre_setup(cls):
super().pre_setup()
from patches import patches
patches.on()
APP_VERSION = "1.0.0"
DATA_UPLOAD_MAX_MEMORY_SIZE = 26214400000
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = values.SecretValue()
DEBUG = values.BooleanValue(True)
ALLOWED_HOSTS = values.ListValue([])
INSTALLED_APPS = [
# internal
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# 3rd party
"django_filters",
"nested_admin",
"polymorphic",
"corsheaders",
"rules",
"django_extensions",
"rest_framework",
"rest_framework.authtoken",
# core apps
"outbo.apps.core",
"outbo.apps.organizations",
"outbo.apps.authentication",
"outbo.apps.projects",
"outbo.apps.products",
"outbo.apps.photobriefing",
"outbo.apps.final_photobriefing",
"outbo.apps.activity_log",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"rules.permissions.ObjectPermissionBackend",
]
ROOT_URLCONF = "outbo.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["outbo/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",
]
},
}
]
WSGI_APPLICATION = "outbo.wsgi.application"
DATABASES = values.DatabaseURLValue()
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 = "pl-PL"
TIME_ZONE = "Europe/Warsaw"
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = "/static/"
MEDIA_URL = "/uploads/"
AUTH_USER_MODEL = "authentication.User"
# DRF
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"outbo.apps.authentication.TokenAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
],
"DEFAULT_RENDERER_CLASSES": (
"djangorestframework_camel_case.render.CamelCaseJSONRenderer",
"djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer",
),
"DEFAULT_PARSER_CLASSES": (
"outbo.apps.core.parsers.CamelCaseNestedMultiPartParser",
"djangorestframework_camel_case.parser.CamelCaseJSONParser",
"djangorestframework_camel_case.parser.CamelCaseFormParser",
),
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend"
],
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
"UPLOADED_FILES_USE_URL": False,
}
CORS_ORIGIN_WHITELIST = values.ListValue([])
USE_X_FORWARDED_HOST = values.BooleanValue(False)
STATIC_ROOT = values.Value()
MEDIA_ROOT = values.Value()
LOCALE_PATHS = [os.path.join(BASE_DIR, "outbo", "locale")]
class Test(Base):
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"outbo.apps.authentication.TokenAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
],
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend"
],
"DEFAULT_PARSER_CLASSES": [
"outbo.apps.core.parsers.NestedMultiPartParser",
"rest_framework.parsers.JSONParser",
"rest_framework.parsers.FormParser",
],
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
"UPLOADED_FILES_USE_URL": False,
}
class Dev(Base):
DOTENV = "dev.env"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
MIDDLEWARE = ["silk.middleware.SilkyMiddleware"] + Base.MIDDLEWARE
INSTALLED_APPS = ["silk"] + Base.INSTALLED_APPS
class Staging(Base):
DEBUG = False
STATIC_ROOT = "/host/static/"
MEDIA_ROOT = "/host/uploads/"
SENTRY_DSN = values.URLValue(environ_required=True)
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
@classmethod
def post_setup(cls):
super().post_setup()
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
sentry_sdk.init(
dsn=str(cls.SENTRY_DSN),
integrations=[DjangoIntegration()],
environment="Staging",
)
class Prod(Base):
DEBUG = False
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
DEFAULT_FILE_STORAGE = "outbo.apps.core.storages.S3MediaStorage"
STATICFILES_STORAGE = "outbo.apps.core.storages.S3StaticStorage"
INSTALLED_APPS = ["anymail"] + Base.INSTALLED_APPS
AWS_ACCESS_KEY_ID = values.Value(environ_required=True)
AWS_SECRET_ACCESS_KEY = values.Value(environ_required=True)
AWS_S3_REGION_NAME = values.Value(environ_required=True)
AWS_S3_ENDPOINT_URL = values.Value(environ_required=True)
AWS_STORAGE_BUCKET_STATIC_NAME = values.Value(environ_required=True)
AWS_STORAGE_BUCKET_MEDIA_NAME = values.Value(environ_required=True)
AWS_S3_FILE_OVERWRITE = values.BooleanValue(False)
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
DEFAULT_FROM_EMAIL = values.Value(environ_required=True)
MAILGUN_API_KEY = values.Value(environ_required=True)
MAILGUN_SENDER_DOMAIN = values.Value(environ_required=True)
@property
def MEDIA_URL(self): # noqa
return (
f"https://{Prod.AWS_S3_ENDPOINT_URL}/{Prod.AWS_STORAGE_BUCKET_MEDIA_NAME}/"
)
@property
def ANYMAIL(self): # noqa
return {
"MAILGUN_API_URL": "https://api.eu.mailgun.net/v3",
"MAILGUN_API_KEY": Prod.MAILGUN_API_KEY,
"MAILGUN_SENDER_DOMAIN": Prod.MAILGUN_SENDER_DOMAIN,
}
SENTRY_DSN = values.URLValue(environ_required=True)
@classmethod
def post_setup(cls):
super().post_setup()
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
sentry_sdk.init(
dsn=str(cls.SENTRY_DSN),
integrations=[DjangoIntegration()],
environment="Production",
)