- Modul Consumable Item: model master, buku besar transaksi (stock ledger), purchase unit conversion, stock opname, dan transaction reversal - Integrasi ke Employee Management, Asset Unit, dan tiket/work order - Konfigurasi akses jaringan lokal (LAN) via 0.0.0.0:8000, ALLOWED_HOSTS, dan CSRF_TRUSTED_ORIGINS otomatis - Script pembuka firewall Windows (buka_firewall_lan.bat) dan menu interaktif run.bat - Skema migrasi 0019_consumableitem_consumabletransaction - Seeder 11 item consumable riil (seed_consumables.py) - Test suite komprehensif (41 automated tests, 100% lulus) - Pipeline CI/CD GitHub Actions (.github/workflows/ci.yml)
241 lines
6.5 KiB
Python
241 lines
6.5 KiB
Python
"""
|
|
Django settings for itam_core project.
|
|
|
|
Generated by 'django-admin startproject' using Django 5.2.17.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
# 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/5.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
DEBUG = os.getenv('DJANGO_DEBUG', 'False').lower() in ('true', '1', 'yes')
|
|
|
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY')
|
|
if not SECRET_KEY:
|
|
if DEBUG:
|
|
SECRET_KEY = 'django-insecure-dev-key-change-in-production'
|
|
else:
|
|
raise ValueError("DJANGO_SECRET_KEY environment variable wajib diset ketika DEBUG=False!")
|
|
|
|
raw_hosts = os.getenv('DJANGO_ALLOWED_HOSTS', '')
|
|
if raw_hosts:
|
|
ALLOWED_HOSTS = [h.strip() for h in raw_hosts.split(',') if h.strip()]
|
|
elif DEBUG:
|
|
ALLOWED_HOSTS = ['*']
|
|
else:
|
|
ALLOWED_HOSTS = []
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'django_htmx',
|
|
|
|
'assets',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'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',
|
|
'django_htmx.middleware.HtmxMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'itam_core.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [BASE_DIR / 'templates'],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
'assets.context_processors.role_context',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'itam_core.wsgi.application'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
|
|
|
import sys
|
|
|
|
db_engine = os.getenv('DB_ENGINE', 'mysql').lower()
|
|
|
|
if 'test' in sys.argv:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': ':memory:',
|
|
}
|
|
}
|
|
elif db_engine in ('sqlite', 'sqlite3'):
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
'NAME': os.getenv('DB_NAME', 'manajemen_aset_it'),
|
|
'USER': os.getenv('DB_USER', 'root'),
|
|
'PASSWORD': os.getenv('DB_PASSWORD', ''),
|
|
'HOST': os.getenv('DB_HOST', '127.0.0.1'),
|
|
'PORT': os.getenv('DB_PORT', '3306'),
|
|
}
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/5.2/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/5.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'id-id'
|
|
|
|
TIME_ZONE = 'Asia/Jakarta'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
STATICFILES_DIRS = [BASE_DIR / 'static']
|
|
DJANGO_VITE = {
|
|
'default': {
|
|
'dev_mode': DEBUG,
|
|
}
|
|
}
|
|
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' if not DEBUG else 'django.contrib.staticfiles.storage.StaticFilesStorage'
|
|
|
|
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = BASE_DIR / 'media'
|
|
|
|
|
|
# Security settings (enabled when DEBUG=False)
|
|
if not DEBUG:
|
|
SECURE_SSL_REDIRECT = os.getenv('SECURE_SSL_REDIRECT', 'False').lower() in ('true', '1', 'yes')
|
|
SECURE_HSTS_SECONDS = 31536000
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
|
SECURE_CONTENT_TYPE_NOSNIFF = True
|
|
SESSION_COOKIE_SECURE = True
|
|
CSRF_COOKIE_SECURE = True
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
|
|
|
raw_csrf = os.getenv('CSRF_TRUSTED_ORIGINS', '')
|
|
CSRF_TRUSTED_ORIGINS = [orig.strip() for orig in raw_csrf.split(',') if orig.strip()]
|
|
|
|
# Tambahkan origin otomatis untuk akses LAN jika DEBUG=True
|
|
if DEBUG:
|
|
for default_origin in ['http://localhost:8000', 'http://127.0.0.1:8000', 'http://0.0.0.0:8000']:
|
|
if default_origin not in CSRF_TRUSTED_ORIGINS:
|
|
CSRF_TRUSTED_ORIGINS.append(default_origin)
|
|
|
|
try:
|
|
import socket
|
|
hostname = socket.gethostname()
|
|
local_ips = socket.gethostbyname_ex(hostname)[2]
|
|
for ip in local_ips:
|
|
origin_ip = f"http://{ip}:8000"
|
|
if origin_ip not in CSRF_TRUSTED_ORIGINS:
|
|
CSRF_TRUSTED_ORIGINS.append(origin_ip)
|
|
except Exception:
|
|
pass
|
|
|
|
# Logging
|
|
LOGGING = {
|
|
'version': 1,
|
|
'disable_existing_loggers': False,
|
|
'formatters': {
|
|
'verbose': {
|
|
'format': '{asctime} {levelname} {module} {message}',
|
|
'style': '{',
|
|
},
|
|
},
|
|
'handlers': {
|
|
'file': {
|
|
'level': 'ERROR',
|
|
'class': 'logging.FileHandler',
|
|
'filename': BASE_DIR / 'error.log',
|
|
'formatter': 'verbose',
|
|
},
|
|
'console': {
|
|
'class': 'logging.StreamHandler',
|
|
'formatter': 'verbose',
|
|
},
|
|
},
|
|
'root': {
|
|
'handlers': ['file', 'console'],
|
|
'level': 'WARNING',
|
|
},
|
|
}
|
|
|
|
LOGIN_URL = 'login'
|