sbt-idp/cope2n-api/fwd/settings.py

230 lines
7.0 KiB
Python
Raw Normal View History

2023-11-30 11:19:06 +00:00
"""
Django settings for fwd project.
Generated by 'django-admin startproject' using Django 4.1.3.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
from pathlib import Path
import environ
from django.urls import reverse_lazy
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env(
2023-12-14 03:54:03 +00:00
DEBUG=(bool, False)
2023-11-30 11:19:06 +00:00
)
2023-12-14 03:54:03 +00:00
DEBUG = False
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
2023-11-30 11:19:06 +00:00
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=['*'] + ['107.120.{}.{}'.format(i, j) for i in range(256) for j in range(256)])
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
2023-12-14 03:54:03 +00:00
SECRET_KEY = env.str("SECRET_KEY", '')
CTEL_KEY = env.str("CTEL_KEY", '')
INTERNAL_SDS_KEY = env.str('SDS_SECRET_KEY', '')
DB_ENCRYPT_KEY = env.str('DB_INTERNAL_KEY', '')
2023-11-30 11:19:06 +00:00
BASE_URL = env.str("BASE_URL", "")
2023-12-14 03:54:03 +00:00
BASE_UI_URL = env.str("BASE_UI_URL", "")
2023-11-30 11:19:06 +00:00
AUTH_TOKEN_LIFE_TIME = env.int("AUTH_TOKEN_LIFE_TIME", 0)
IMAGE_TOKEN_LIFE_TIME = env.int("IMAGE_TOKEN_LIFE_TIME", 0)
ADMIN_USER_NAME = env.str("ADMIN_USER_NAME", "")
ADMIN_PASSWORD = env.str("ADMIN_PASSWORD", '')# SECURITY WARNING: don't run with debug turned on in production!
STANDARD_USER_NAME = env.str("STANDARD_USER_NAME", "")
STANDARD_PASSWORD = env.str("STANDARD_PASSWORD", '')# SECURITY WARNING: don't run with debug turned on in production!
2023-11-30 11:19:06 +00:00
# Application definition
S3_ENDPOINT = env.str("S3_ENDPOINT", "")
2023-12-14 03:54:03 +00:00
S3_ACCESS_KEY = env.str("S3_ACCESS_KEY", "")
S3_SECRET_KEY = env.str("S3_SECRET_KEY", "")
2023-11-30 11:19:06 +00:00
S3_BUCKET_NAME = env.str("S3_BUCKET_NAME", "ocr-data")
2023-12-13 11:43:10 +00:00
REDIS_HOST = env.str("REDIS_HOST", "result-cache")
REDIS_PORT = env.int("REDIS_PORT", 6379)
2023-11-30 11:19:06 +00:00
INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
'fwd_api.apps.FwdApiConfig',
'django.contrib.admin',
'rest_framework',
'drf_spectacular',
'drf_spectacular_sidecar', # required for Django collectstatic discovery
'corsheaders',
]
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",
'corsheaders.middleware.CorsMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.middleware.locale.LocaleMiddleware",
]
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale')
]
ROOT_URLCONF = "fwd.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 = "fwd.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = {
'default': {
2023-12-05 05:59:59 +00:00
'ENGINE': env.str("DB_ENGINE"),
'NAME': env.str("DB_SCHEMA"),
2023-11-30 11:19:06 +00:00
'USER': env.str("DB_USER", None),
'PASSWORD': env.str("DB_PASSWORD", None),
'HOST': env.str("DB_HOST", None),
'PORT': env.str("DB_PORT", None),
2023-12-26 11:44:03 +00:00
'CONN_MAX_AGE': None,
2023-11-30 11:19:06 +00:00
}
}
# Password validation
# https://docs.djangoproject.com/en/4.1/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/4.1/topics/i18n/
LANGUAGE_CODE = "en-us"
USE_I18N = True
2023-12-13 09:01:31 +00:00
CELERY_ENABLE_UTC = False
CELERY_TIMEZONE = "Asia/Ho_Chi_Minh"
TIME_ZONE = "Asia/Ho_Chi_Minh"
2023-11-30 11:19:06 +00:00
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STORAGES = {
# ...
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
REST_FRAMEWORK = {
# YOUR SETTINGS
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
# 'DEFAULT_SCHEMA_CLASS': 'fwd_api.schema.AutoSchema',
"DEFAULT_AUTHENTICATION_CLASSES": (
"fwd_api.filter.AuthFilter.AuthFilter",
),
'EXCEPTION_HANDLER': 'fwd_api.exception.exceptions_handler.custom_exception_handler',
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework_xml.renderers.XMLRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
),
}
SPECTACULAR_SETTINGS = {
2023-12-15 05:43:19 +00:00
'TITLE': 'OCR Engine for Invoices',
'DESCRIPTION': 'AI Powered by Samsung SDS Vietnam',
2023-11-30 11:19:06 +00:00
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': True,
# OTHER SETTINGS
'SWAGGER_UI_DIST': 'SIDECAR', # shorthand to use the sidecar instead
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
'REDOC_DIST': 'SIDECAR',
# OTHER SETTINGS
"PREPROCESSING_HOOKS": ["fwd_api.api_specs.hooks.remove_apis_from_list"],
# Custom Spectacular Settings
"EXCLUDE_PATH": [reverse_lazy("schema")],
"EXCLUDE_RELATIVE_PATH": ["/rsa", '/gen-token', '/app/'],
2023-12-15 05:43:19 +00:00
"TAGS": [
"Login",
"OCR",
"Data",
"System",
],
"TAGS_SORTER": "alpha"
2023-11-30 11:19:06 +00:00
}
FILE_UPLOAD_HANDLERS = [
'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]
CORS_ORIGIN_ALLOW_ALL = True
MEDIA_ROOT = env.str("MEDIA_ROOT", default=r"/var/www/example.com/media/")
BROKER_URL = env.str("BROKER_URL", default="amqp://test:test@107.120.70.226:5672//")
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60
2023-12-26 11:44:03 +00:00
MAX_UPLOAD_SIZE_OF_A_FILE = 5 * 1024 * 1024 # 5 MB
2023-11-30 11:19:06 +00:00
MAX_UPLOAD_FILE_SIZE_OF_A_REQUEST = 100 * 1024 * 1024 # 100 MB
MAX_UPLOAD_FILES_IN_A_REQUEST = 5
2023-12-11 13:15:48 +00:00
MAX_PIXEL_IN_A_FILE = 5000
2023-12-12 05:54:34 +00:00
TARGET_MAX_IMAGE_SIZE = (2048, 2048)
2023-11-30 11:19:06 +00:00
SIZE_TO_COMPRESS = 2 * 1024 * 1024
MAX_NUMBER_OF_TEMPLATE = 3
MAX_PAGES_OF_PDF_FILE = 50
2023-12-05 05:59:59 +00:00
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
2023-12-12 05:54:34 +00:00
}