init: initial Django LMS backend
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for core 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/6.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
@@ -0,0 +1,196 @@
|
||||
"""
|
||||
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 = 'django-insecure-vk@6jztjz7k6hb2%x%toy0*1&##oy%v%%c$o32w*ptq)+-b0$5'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
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',
|
||||
'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', 'my_db'),
|
||||
'HOST': os.environ.get('DB_HOST', 'localhost'),
|
||||
'PORT': os.environ.get('DB_PORT', '5432'), # พอร์ตมาตรฐาน PostgreSQL
|
||||
'USER': os.environ.get('DB_USER', 'user'),
|
||||
'PASSWORD': os.environ.get('DB_PASSWORD', 'password'),
|
||||
'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_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",
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
URL configuration for core project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/6.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for core 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/6.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in New Issue
Block a user