2026-02-19 17:55:33 +03:30
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
2026-03-19 22:54:29 +03:30
|
|
|
LOG_DIR = Path(os.environ.get("LOG_DIR", BASE_DIR / "logs"))
|
|
|
|
|
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
2026-02-19 17:55:33 +03:30
|
|
|
|
|
|
|
|
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(",")
|
|
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
|
"django.contrib.admin",
|
|
|
|
|
"django.contrib.auth",
|
|
|
|
|
"django.contrib.contenttypes",
|
|
|
|
|
"django.contrib.sessions",
|
|
|
|
|
"django.contrib.messages",
|
|
|
|
|
"django.contrib.staticfiles",
|
|
|
|
|
"rest_framework",
|
|
|
|
|
"corsheaders",
|
2026-03-19 22:54:29 +03:30
|
|
|
"drf_spectacular",
|
|
|
|
|
"drf_spectacular_sidecar",
|
2026-02-27 19:37:02 +03:30
|
|
|
"rag",
|
2026-02-27 13:09:00 +03:30
|
|
|
"tasks",
|
2026-03-19 22:54:29 +03:30
|
|
|
"location_data",
|
2026-02-27 13:31:16 +03:30
|
|
|
"sensor_data",
|
2026-03-19 22:54:29 +03:30
|
|
|
"weather",
|
|
|
|
|
"plant",
|
|
|
|
|
"irrigation",
|
2026-03-21 23:50:36 +03:30
|
|
|
"fertilization",
|
2026-02-19 17:55:33 +03:30
|
|
|
]
|
|
|
|
|
|
|
|
|
|
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", "ai"),
|
|
|
|
|
"USER": os.environ.get("DB_USER", "ai"),
|
|
|
|
|
"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.AllowAny",
|
|
|
|
|
],
|
2026-03-19 22:54:29 +03:30
|
|
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SPECTACULAR_SETTINGS = {
|
|
|
|
|
"TITLE": "CropLogic AI API",
|
|
|
|
|
"DESCRIPTION": "APIهای هوش مصنوعی CropLogic — داده خاک، سنسور، هواشناسی و چت RAG",
|
|
|
|
|
"VERSION": "1.0.0",
|
|
|
|
|
"SERVE_INCLUDE_SCHEMA": False,
|
|
|
|
|
"SWAGGER_UI_DIST": "SIDECAR",
|
|
|
|
|
"SWAGGER_UI_FAVICON_HREF": "SIDECAR",
|
|
|
|
|
"REDOC_DIST": "SIDECAR",
|
|
|
|
|
"COMPONENT_SPLIT_REQUEST": True,
|
|
|
|
|
"TAGS": [
|
|
|
|
|
{"name": "RAG Chat", "description": "چت هوشمند RAG"},
|
|
|
|
|
{"name": "Tasks", "description": "مدیریت تسکهای Celery"},
|
|
|
|
|
{"name": "Soil Data", "description": "دادههای خاک (SoilGrids)"},
|
|
|
|
|
{"name": "Sensor Data", "description": "دادههای سنسور"},
|
|
|
|
|
{"name": "Sensor Parameters", "description": "پارامترهای سنسور"},
|
|
|
|
|
],
|
2026-02-19 17:55:33 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CORS_ALLOW_ALL_ORIGINS = DEBUG
|
2026-02-27 13:09:00 +03:30
|
|
|
|
|
|
|
|
# Celery
|
|
|
|
|
CELERY_BROKER_URL = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379/0")
|
|
|
|
|
CELERY_RESULT_BACKEND = os.environ.get("CELERY_RESULT_BACKEND", "redis://localhost:6379/0")
|
|
|
|
|
CELERY_ACCEPT_CONTENT = ["json"]
|
|
|
|
|
CELERY_TASK_SERIALIZER = "json"
|
2026-02-27 20:06:46 +03:30
|
|
|
|
|
|
|
|
# Celery Beat — embed دیتای کاربران هر ۶ ساعت
|
|
|
|
|
CELERY_BEAT_SCHEDULE = {
|
|
|
|
|
"rag-ingest-periodic": {
|
|
|
|
|
"task": "rag.tasks.rag_ingest_task",
|
|
|
|
|
"schedule": 6 * 60 * 60, # ۶ ساعت
|
|
|
|
|
},
|
2026-03-19 22:54:29 +03:30
|
|
|
"weather-fetch-periodic": {
|
|
|
|
|
"task": "weather.tasks.fetch_weather_all_locations_task",
|
|
|
|
|
"schedule": 6 * 60 * 60, # ۶ ساعت
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Weather API
|
|
|
|
|
WEATHER_API_BASE_URL = os.environ.get(
|
|
|
|
|
"WEATHER_API_BASE_URL", "https://api.open-meteo.com/v1/forecast"
|
|
|
|
|
)
|
|
|
|
|
WEATHER_API_KEY = os.environ.get("WEATHER_API_KEY", "")
|
|
|
|
|
|
|
|
|
|
LOGGING = {
|
|
|
|
|
"version": 1,
|
|
|
|
|
"disable_existing_loggers": False,
|
|
|
|
|
"formatters": {
|
|
|
|
|
"standard": {
|
|
|
|
|
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"handlers": {
|
|
|
|
|
"console": {
|
|
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
|
"formatter": "standard",
|
|
|
|
|
},
|
|
|
|
|
"file": {
|
|
|
|
|
"class": "logging.handlers.TimedRotatingFileHandler",
|
|
|
|
|
"filename": str(LOG_DIR / "app.log"),
|
|
|
|
|
"when": "midnight",
|
|
|
|
|
"backupCount": 14,
|
|
|
|
|
"encoding": "utf-8",
|
|
|
|
|
"formatter": "standard",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"loggers": {
|
|
|
|
|
"django": {
|
|
|
|
|
"handlers": ["console", "file"],
|
|
|
|
|
"level": os.environ.get("DJANGO_LOG_LEVEL", "INFO"),
|
|
|
|
|
"propagate": False,
|
|
|
|
|
},
|
|
|
|
|
"rag": {
|
|
|
|
|
"handlers": ["console", "file"],
|
|
|
|
|
"level": os.environ.get("RAG_LOG_LEVEL", "INFO"),
|
|
|
|
|
"propagate": False,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"root": {
|
|
|
|
|
"handlers": ["console", "file"],
|
|
|
|
|
"level": os.environ.get("ROOT_LOG_LEVEL", "INFO"),
|
|
|
|
|
},
|
2026-02-27 20:06:46 +03:30
|
|
|
}
|