inicialização do repo
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for aprovacao_pedidos project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aprovacao_pedidos.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@@ -0,0 +1,35 @@
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LogIPMiddleware:
|
||||
"""Middleware para logar o IP de cada requisição"""
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
# Obtém o IP do cliente
|
||||
ip = self.get_client_ip(request)
|
||||
|
||||
# Loga o IP da requisição
|
||||
print(f"Request from IP: {ip}")
|
||||
logger.info(f"Request from IP: {ip} - Method: {request.method} - Path: {request.path}")
|
||||
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
|
||||
def get_client_ip(self, request):
|
||||
"""
|
||||
Obtém o IP real do cliente, considerando proxies
|
||||
"""
|
||||
# Verifica se há X-Forwarded-For (quando atrás de proxy/load balancer)
|
||||
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||
if x_forwarded_for:
|
||||
ip = x_forwarded_for.split(',')[0].strip()
|
||||
else:
|
||||
# Caso contrário, usa REMOTE_ADDR
|
||||
ip = request.META.get('REMOTE_ADDR')
|
||||
|
||||
return ip
|
||||
@@ -0,0 +1,192 @@
|
||||
"""
|
||||
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 = os.getenv('CSRF_TRUSTED_ORIGINS', 'http://localhost:8000,http://127.0.0.1:8000').split(',')
|
||||
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/'
|
||||
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
URL configuration for aprovacao_pedidos project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/5.2/topics/http/urls/
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from home import views as home_views
|
||||
from django.http import HttpResponse
|
||||
|
||||
def healthz(request):
|
||||
"""Health check endpoint"""
|
||||
return HttpResponse(status=200)
|
||||
|
||||
urlpatterns = [
|
||||
path('healthz', healthz, name='healthz'),
|
||||
path('admin/', admin.site.urls),
|
||||
path('home/', include('home.urls')),
|
||||
path('', home_views.home_page, name='home'),
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for aprovacao_pedidos project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'aprovacao_pedidos.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user