199 lines
6.2 KiB
Python
199 lines
6.2 KiB
Python
"""
|
|
Django settings for core project.
|
|
|
|
Generated by 'django-admin startproject' using Django 6.0.2.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/6.0/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/6.0/ref/settings/
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from django.templatetags.static import static
|
|
|
|
# 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/6.0/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.environ.get("SECRET_KEY", "unsafe-dev-secret")
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = False
|
|
|
|
ALLOWED_HOSTS = ["*"]
|
|
|
|
# Application definition
|
|
INSTALLED_APPS = [
|
|
"unfold", # ต้องอยู่บนสุด ก่อน django.contrib.admin
|
|
"unfold.contrib.filters", # Filter สวย ๆ
|
|
"unfold.contrib.forms", # ฟอร์มสวย ๆ
|
|
"unfold.contrib.import_export", # ใช้คู่กับ import_export
|
|
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
|
|
# Third-party Apps
|
|
'rest_framework', # สำหรับจัดการ API
|
|
'corsheaders', # สำหรับจัดการ CORS (สำคัญมากถ้ามีหน้าบ้านแยก)
|
|
|
|
# LOCAL APPS
|
|
'apps.accounts',
|
|
'apps.content',
|
|
'apps.courses',
|
|
'apps.common',
|
|
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'corsheaders.middleware.CorsMiddleware', # สำคัญมากสำหรับ Frontend
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'whitenoise.middleware.WhiteNoiseMiddleware',
|
|
'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 = 'core.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 = 'core.wsgi.application'
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.postgresql', # เปลี่ยนจาก django_cockroachdb
|
|
'NAME': os.environ.get('DB_NAME', 'lms'),
|
|
'HOST': os.environ.get('DB_HOST', 'localhost'),
|
|
'PORT': os.environ.get('DB_PORT', '5432'), # พอร์ตมาตรฐาน PostgreSQL
|
|
'USER': os.environ.get('DB_USER', 'lms'),
|
|
'PASSWORD': os.environ.get('DB_PASSWORD', 'lms123'),
|
|
'OPTIONS': {
|
|
'connect_timeout': 5,
|
|
},
|
|
'ATOMIC_REQUESTS': True, # PostgreSQL รองรับ Atomic Requests ได้อย่างมีประสิทธิภาพ
|
|
},
|
|
|
|
}
|
|
|
|
REST_FRAMEWORK = {
|
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
|
"rest_framework.authentication.SessionAuthentication",
|
|
"rest_framework.authentication.TokenAuthentication",
|
|
),
|
|
}
|
|
|
|
CORS_ALLOW_ALL_ORIGINS = True # ควรเป็น False ใน Production
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/6.0/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/6.0/topics/i18n/
|
|
|
|
# เปลี่ยนเป็นภาษาไทยสำหรับหน้า Admin
|
|
LANGUAGE_CODE = 'th'
|
|
# ตั้งเป็นเวลาประเทศไทย
|
|
TIME_ZONE = 'Asia/Bangkok'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
|
|
|
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
|
|
|
STATICFILES_DIRS = [
|
|
os.path.join(BASE_DIR, 'static'),
|
|
]
|
|
|
|
AUTH_USER_MODEL = "accounts.CustomUser"
|
|
|
|
# ตั้งค่าเมนูและ Dashboard (UNFOLD Configuration)
|
|
UNFOLD = {
|
|
"SITE_TITLE": "LMS เพื่อสาธารณะ",
|
|
"SITE_HEADER": "ระบบคลังความรู้เพื่อเยาวชนไทย",
|
|
"SITE_SYMBOL": "menu_book",
|
|
"SHOW_HISTORY": True,
|
|
"STYLES": [
|
|
lambda request: static("css/unfold_th_font.css"),
|
|
],
|
|
"SCRIPTS": [
|
|
lambda request: static("unfold/js/admin.js"),
|
|
],
|
|
|
|
|
|
"COLORS": {
|
|
"primary": {
|
|
"50": "#e0f2fe", # ฟ้าอ่อนมาก (ใช้กับพื้นหลังอ่อน)
|
|
"100": "#bae6fd",
|
|
"200": "#7dd3fc",
|
|
"300": "#38bdf8",
|
|
"400": "#0ea5e9",
|
|
"500": "#0284c7", # สีหลัก
|
|
"600": "#0369a1",
|
|
"700": "#075985",
|
|
"800": "#0c4a6e",
|
|
"900": "#082f49",
|
|
"950": "#020617",
|
|
},
|
|
# ถ้าอยากปรับโทนสีเทา/พื้นหลัง (Base) ให้เข้มขรึมขึ้น
|
|
"base": {
|
|
"50": "#f8fafc",
|
|
"900": "#0f172a", # สีพื้นหลัง Dark Mode
|
|
"950": "#020617",
|
|
},
|
|
},
|
|
|
|
} |