Files
tianxuan/tianxuan/settings.py
T
PM-pinou 9314ac6942 chore: bump version to v1.1.2
- New timeline UI: interleaved LLM reasoning + tool call display
- Fix: run_log truncation for large tool outputs
- Fix: lat/lon + values reduced to ~1% (was 99%)
- Fix: @csrf_exempt on upload/delete endpoints
- Fix: DATA_UPLOAD_MAX_NUMBER_FILES for 1998-file upload
- Fix: dtype alignment for multi-batch CSV processing
- New: tests/test_e2e_full.py with real DeepSeek LLM
- New: 1998-file test data generator
2026-07-20 23:32:32 +08:00

153 lines
4.4 KiB
Python

import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
os.makedirs(BASE_DIR / "logs", exist_ok=True)
# Application data directory (user data, outside project for clean updates)
_APP_DATA = Path(os.environ.get('APPDATA', str(Path.home() / '.tianxuan'))) / 'TianXuan'
_APP_DATA.mkdir(parents=True, exist_ok=True)
SECRET_KEY = "django-insecure-change-me-in-production"
DEBUG = True
import socket
hostname = socket.gethostname()
try:
local_ip = socket.gethostbyname(hostname)
except:
local_ip = "127.0.0.1"
ALLOWED_HOSTS = ["localhost", "127.0.0.1", hostname, local_ip, "*"]
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"analysis.apps.AnalysisConfig",
]
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 = "tianxuan.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"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",
],
},
},
]
WSGI_APPLICATION = "tianxuan.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": str(_APP_DATA / "db.sqlite3"),
'OPTIONS': {'timeout': 20},
}
}
CONN_MAX_AGE = 0
# Set SQLite journal mode to DELETE to avoid WAL files during compression
from django.db.backends.signals import connection_created
def _set_sqlite_journal(sender, connection, **kwargs):
if connection.vendor == "sqlite":
with connection.cursor() as cursor:
try:
cursor.execute("PRAGMA journal_mode=WAL;")
except Exception:
pass
try:
cursor.execute("PRAGMA synchronous=NORMAL;")
except Exception:
pass
try:
cursor.execute("PRAGMA cache_size=-20000;")
except Exception:
pass
try:
cursor.execute("PRAGMA temp_store=MEMORY;")
except Exception:
pass
try:
cursor.execute("PRAGMA mmap_size=3000000000;")
except Exception:
pass
connection_created.connect(_set_sqlite_journal)
AUTH_PASSWORD_VALIDATORS = []
LANGUAGE_CODE = "zh-hans"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000000
DATA_UPLOAD_MAX_NUMBER_FILES = 10000
DATA_UPLOAD_MAX_MEMORY_SIZE = 256 * 1024 * 1024
FILE_UPLOAD_MAX_MEMORY_SIZE = 100 * 1024 * 1024
STATIC_URL = "static/"
STATICFILES_DIRS = [BASE_DIR / "static"]
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {"format": "[{asctime}] {levelname} {name}: {message}", "style": "{"}
},
"handlers": {
"file": {
"class": "logging.handlers.RotatingFileHandler",
"filename": BASE_DIR / "logs" / "tianxuan.log",
"maxBytes": 10485760,
"backupCount": 5,
"formatter": "verbose",
"encoding": "utf-8",
},
"stderr": {"class": "logging.StreamHandler", "formatter": "verbose"},
},
"root": {"handlers": ["file", "stderr"], "level": "INFO"},
}
# Dynamically add the configured server host to ALLOWED_HOSTS.
# When the config host is 0.0.0.0 the wildcard "*" (already set above) covers
# all addresses; for a specific IP/DNS name we add it explicitly.
try:
from config import get_config
_cfg = get_config()
_ch = _cfg.server.host
if _ch and _ch not in ALLOWED_HOSTS and _ch != "0.0.0.0":
ALLOWED_HOSTS.append(_ch)
except Exception:
pass