162 lines
4.7 KiB
Python
162 lines
4.7 KiB
Python
import os
|
|
from datetime import timedelta
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
SECRET_KEY = os.environ.get("SECRET_KEY", "django-insecure-dev-only")
|
|
DEBUG = os.environ.get("DEBUG", "0") == "1"
|
|
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "localhost,127.0.0.1").split(",")
|
|
|
|
AUTH_USER_MODEL = "account.User"
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
"account.backends.MultiFieldBackend",
|
|
]
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"auth.apps.AuthConfig",
|
|
"account.apps.AccountConfig",
|
|
"sensor_hub.apps.SensorHubConfig",
|
|
"dashboard",
|
|
"crop_zoning",
|
|
"plant_simulator",
|
|
"pest_detection",
|
|
"irrigation_recommendation",
|
|
"fertilization_recommendation",
|
|
"farm_ai_assistant",
|
|
"external_api_adapter.apps.ExternalApiAdapterConfig",
|
|
"rest_framework",
|
|
"drf_spectacular",
|
|
"drf_spectacular_sidecar",
|
|
"corsheaders",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"corsheaders.middleware.CorsMiddleware",
|
|
"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"
|
|
WSGI_APPLICATION = "config.wsgi.application"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [],
|
|
"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",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": os.environ.get("DB_ENGINE", "django.db.backends.mysql"),
|
|
"NAME": os.environ.get("DB_NAME", "croplogic"),
|
|
"USER": os.environ.get("DB_USER", "croplogic"),
|
|
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
|
|
"HOST": os.environ.get("DB_HOST", "127.0.0.1"),
|
|
"PORT": os.environ.get("DB_PORT", "3306"),
|
|
"OPTIONS": {
|
|
"charset": "utf8mb4",
|
|
},
|
|
}
|
|
}
|
|
|
|
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 = "en-us"
|
|
TIME_ZONE = "UTC"
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = "static/"
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
|
"LOCATION": "croplogic-auth-otp",
|
|
}
|
|
}
|
|
|
|
REST_FRAMEWORK = {
|
|
"DEFAULT_PERMISSION_CLASSES": [
|
|
"rest_framework.permissions.IsAuthenticated",
|
|
],
|
|
"DEFAULT_AUTHENTICATION_CLASSES": [
|
|
"rest_framework_simplejwt.authentication.JWTAuthentication",
|
|
],
|
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
|
}
|
|
|
|
SPECTACULAR_SETTINGS = {
|
|
"TITLE": "CropLogic API",
|
|
"DESCRIPTION": "Swagger/OpenAPI documentation for all CropLogic API endpoints.",
|
|
"VERSION": "1.0.0",
|
|
"SERVE_INCLUDE_SCHEMA": False,
|
|
"SWAGGER_UI_DIST": "SIDECAR",
|
|
"SWAGGER_UI_FAVICON_HREF": "SIDECAR",
|
|
"REDOC_DIST": "SIDECAR",
|
|
"SCHEMA_PATH_PREFIX": r"/api/",
|
|
"SERVE_PERMISSIONS": ["rest_framework.permissions.AllowAny"],
|
|
}
|
|
|
|
|
|
SMS_IR_API_KEY = os.environ.get("SMS_IR_API_KEY", "")
|
|
SMS_IR_LINE_NUMBER = int(os.environ.get("SMS_IR_LINE_NUMBER", "300000000000"))
|
|
|
|
CORS_ALLOW_ALL_ORIGINS = DEBUG
|
|
|
|
USE_EXTERNAL_API_MOCK = os.getenv("USE_EXTERNAL_API_MOCK", "false").lower() == "true"
|
|
EXTERNAL_API_TIMEOUT = int(os.getenv("EXTERNAL_API_TIMEOUT", "30"))
|
|
|
|
EXTERNAL_SERVICES = {
|
|
"ai": {
|
|
"base_url": os.getenv("AI_SERVICE_BASE_URL", ""),
|
|
"api_key": os.getenv("AI_SERVICE_API_KEY", ""),
|
|
},
|
|
"sensor_hub": {
|
|
"base_url": os.getenv("SENSOR_HUB_SERVICE_BASE_URL", ""),
|
|
"api_key": os.getenv("SENSOR_HUB_SERVICE_API_KEY", ""),
|
|
},
|
|
}
|
|
|
|
|
|
SIMPLE_JWT = {
|
|
"ACCESS_TOKEN_LIFETIME": timedelta(days=7),
|
|
"REFRESH_TOKEN_LIFETIME": timedelta(days=7),
|
|
"ROTATE_REFRESH_TOKENS": False,
|
|
"BLACKLIST_AFTER_ROTATION": False,
|
|
}
|