196 lines
6.0 KiB
Python
196 lines
6.0 KiB
Python
"""
|
|
Django settings for aprovacao_pedidos project.
|
|
|
|
Generated by 'django-admin startproject' using Django 5.2.5.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import os
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
from dotenv import load_dotenv
|
|
|
|
# Carregar variáveis de ambiente do arquivo .env
|
|
load_dotenv()
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.getenv('SECRET_KEY')
|
|
if not SECRET_KEY and not DEBUG:
|
|
raise ImproperlyConfigured("SECRET_KEY obrigatoria quando DEBUG=False.")
|
|
if not SECRET_KEY:
|
|
SECRET_KEY = "dev-only-secret-key-change-me"
|
|
|
|
# Definir ALLOWED_HOSTS baseado no ambiente
|
|
ALLOWED_HOSTS = [h.strip() for h in os.getenv('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',') if h.strip()]
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"home",
|
|
]
|
|
|
|
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',
|
|
'aprovacao_pedidos.middleware.LogIPMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'aprovacao_pedidos.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'aprovacao_pedidos.wsgi.application'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
|
|
|
# SQLite para desenvolvimento
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
# SQL Server (comentado - descomente após instalar django-pyodbc-azure)
|
|
# DATABASES = {
|
|
# 'default': {
|
|
# 'ENGINE': 'mssql',
|
|
# 'NAME': 'your_database_name', # MODIFICAR: seu nome do banco
|
|
# 'USER': 'your_user', # MODIFICAR: seu usuário
|
|
# 'PASSWORD': 'your_password', # MODIFICAR: sua senha
|
|
# 'HOST': '10.77.77.10', # MODIFICAR: seu servidor SQL Server
|
|
# 'PORT': '1433',
|
|
# 'OPTIONS': {
|
|
# 'driver': 'ODBC Driver 17 for SQL Server',
|
|
# }
|
|
# }
|
|
# }
|
|
|
|
# Configuração SQL Server para queries raw (sem ORM) - carregada do .env
|
|
SQL_SERVER_CONFIG = {
|
|
'SERVER': os.getenv('SQL_SERVER_HOST', '10.77.77.10'),
|
|
'DATABASE': os.getenv('SQL_SERVER_DATABASE', 'GINSENG'),
|
|
'USERNAME': os.getenv('SQL_SERVER_USERNAME', 'suprimentos'),
|
|
'PASSWORD': os.getenv('SQL_SERVER_PASSWORD', ''),
|
|
}
|
|
|
|
# Configuração da API de Suprimentos (carregada do .env)
|
|
API_SUPRIMENTOS_CONFIG = {
|
|
'TOKEN': os.getenv('API_SUPRIMENTOS_TOKEN', ''),
|
|
'DETALHE_URL': os.getenv('API_SUPRIMENTOS_DETALHE_URL', 'https://api.grupoginseng.com.br/api/suprimentos_detalhepedido?limit=50000&status=pendente'),
|
|
'IMPLANTACAO_URL': os.getenv('API_SUPRIMENTOS_IMPLANTACAO_URL', 'https://api.grupoginseng.com.br/api/vw_suprimentos_implantacaopedido?limit=50000'),
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
|
|
|
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',
|
|
},
|
|
]
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'pt-br'
|
|
|
|
TIME_ZONE = 'America/Sao_Paulo'
|
|
|
|
USE_I18N = False
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
|
|
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
# CSRF e segurança
|
|
CSRF_TRUSTED_ORIGINS = [origin.strip() for origin in os.getenv(
|
|
'CSRF_TRUSTED_ORIGINS',
|
|
'http://localhost:8000,http://127.0.0.1:8000'
|
|
).split(',') if origin.strip()]
|
|
SESSION_COOKIE_SECURE = not DEBUG
|
|
CSRF_COOKIE_SECURE = not DEBUG
|
|
SESSION_COOKIE_HTTPONLY = True
|
|
CSRF_COOKIE_HTTPONLY = True
|
|
SECURE_CONTENT_TYPE_NOSNIFF = True
|
|
X_FRAME_OPTIONS = 'DENY'
|
|
SECURE_REFERRER_POLICY = 'same-origin'
|
|
|
|
# Quando o app estiver atrás de proxy reverso/TLS terminando no proxy.
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
USE_X_FORWARDED_HOST = True
|
|
SECURE_SSL_REDIRECT = os.getenv('SECURE_SSL_REDIRECT', 'False').lower() == 'true'
|
|
SECURE_HSTS_SECONDS = int(os.getenv('SECURE_HSTS_SECONDS', '0'))
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = os.getenv('SECURE_HSTS_INCLUDE_SUBDOMAINS', 'False').lower() == 'true'
|
|
SECURE_HSTS_PRELOAD = os.getenv('SECURE_HSTS_PRELOAD', 'False').lower() == 'true'
|
|
|
|
# Login redirect
|
|
LOGIN_URL = '/'
|
|
LOGIN_REDIRECT_URL = '/home/'
|