168 lines
4.6 KiB
Python
168 lines
4.6 KiB
Python
"""Django settings for autocensup."""
|
|
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse
|
|
|
|
import os
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def load_env_file(path: Path) -> None:
|
|
if not path.exists():
|
|
return
|
|
|
|
for line in path.read_text().splitlines():
|
|
line = line.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
|
|
key, value = line.split("=", 1)
|
|
key = key.strip()
|
|
value = value.strip().strip("'\"")
|
|
if key:
|
|
os.environ.setdefault(key, value)
|
|
|
|
|
|
load_env_file(BASE_DIR / ".env")
|
|
|
|
SECRET_KEY = os.getenv(
|
|
"DJANGO_SECRET_KEY",
|
|
"django-insecure-dev-only-change-me",
|
|
)
|
|
|
|
DEBUG = os.getenv("DJANGO_DEBUG", "True").lower() in {"1", "true", "yes", "on"}
|
|
|
|
ALLOWED_HOSTS = [
|
|
host.strip()
|
|
for host in os.getenv(
|
|
"DJANGO_ALLOWED_HOSTS",
|
|
"autocensup.solucaoti.net.br,localhost,127.0.0.1,0.0.0.0",
|
|
).split(",")
|
|
if host.strip()
|
|
]
|
|
|
|
CSRF_TRUSTED_ORIGINS = [
|
|
origin.strip()
|
|
for origin in os.getenv(
|
|
"DJANGO_CSRF_TRUSTED_ORIGINS",
|
|
"https://autocensup.solucaoti.net.br",
|
|
).split(",")
|
|
if origin.strip()
|
|
]
|
|
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"core",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
]
|
|
|
|
ROOT_URLCONF = "config.urls"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [BASE_DIR / "templates"],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
"core.context_processors.ano_censo",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = "config.wsgi.application"
|
|
|
|
|
|
def database_config() -> dict[str, str | int]:
|
|
database_url = os.getenv("DATABASE_URL")
|
|
|
|
if database_url:
|
|
parsed = urlparse(database_url)
|
|
return {
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
"NAME": parsed.path.removeprefix("/"),
|
|
"USER": parsed.username or "",
|
|
"PASSWORD": parsed.password or "",
|
|
"HOST": parsed.hostname or "",
|
|
"PORT": parsed.port or 5432,
|
|
}
|
|
|
|
return {
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
"NAME": os.getenv("POSTGRES_DB", "autocensup"),
|
|
"USER": os.getenv("POSTGRES_USER", "autocensup"),
|
|
"PASSWORD": os.getenv("POSTGRES_PASSWORD", "autocensup"),
|
|
"HOST": os.getenv("POSTGRES_HOST", "localhost"),
|
|
"PORT": int(os.getenv("POSTGRES_PORT", "5432")),
|
|
}
|
|
|
|
|
|
DATABASES = {
|
|
"default": database_config(),
|
|
}
|
|
|
|
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 = "pt-br"
|
|
TIME_ZONE = "America/Fortaleza"
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = "static/"
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
LOGIN_URL = "login"
|
|
LOGIN_REDIRECT_URL = "home"
|
|
LOGOUT_REDIRECT_URL = "login"
|
|
|
|
GENNERA_LOCAL_BASE_URL = os.getenv("GENNERA_LOCAL_BASE_URL", "http://gennera.solucaoti.net.br")
|
|
GENNERA_API_TOKEN = os.getenv("API_TOKEN", "")
|
|
GENNERA_LOCAL_AUTH_TOKEN = os.getenv("GENNERA_LOCAL_AUTH_TOKEN", "")
|
|
|
|
CENSUP_IES_CODIGO = os.getenv("CENSUP_IES_CODIGO", "")
|
|
|
|
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
|
|
CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0")
|
|
CELERY_TASK_SERIALIZER = "json"
|
|
CELERY_RESULT_SERIALIZER = "json"
|
|
CELERY_ACCEPT_CONTENT = ["json"]
|
|
CELERY_TASK_TRACK_STARTED = True
|
|
CELERY_TIMEZONE = TIME_ZONE
|
|
CELERY_RESULT_EXTENDED = True
|