model.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # coding=utf-8
  2. """
  3. @project: MaxKB
  4. @Author:虎虎
  5. @file: model.py
  6. @date:2025/11/5 14:53
  7. @desc:
  8. """
  9. from pathlib import Path
  10. from ...const import CONFIG, PROJECT_DIR
  11. import os
  12. from django.utils.translation import gettext_lazy as _
  13. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  14. BASE_DIR = Path(__file__).resolve().parent.parent.parent
  15. # Quick-start development settings - unsuitable for production
  16. # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
  17. # SECURITY WARNING: keep the secret key used in production secret!
  18. SECRET_KEY = CONFIG.get("SECRET_KEY") or 'django-insecure-zm^1_^i5)3gp^&0io6zg72&z!a*d=9kf9o2%uft+27l)+t(#3e'
  19. # SECURITY WARNING: don't run with debug turned on in production!
  20. DEBUG = CONFIG.get_debug()
  21. ALLOWED_HOSTS = ['*']
  22. # Application definition
  23. INSTALLED_APPS = [
  24. 'django.contrib.contenttypes',
  25. 'django.contrib.messages',
  26. 'django.contrib.staticfiles',
  27. 'rest_framework',
  28. 'local_model',
  29. ]
  30. MIDDLEWARE = [
  31. 'django.middleware.locale.LocaleMiddleware',
  32. 'django.middleware.security.SecurityMiddleware',
  33. 'django.contrib.sessions.middleware.SessionMiddleware',
  34. ]
  35. REST_FRAMEWORK = {
  36. 'EXCEPTION_HANDLER': 'common.exception.handle_exception.handle_exception',
  37. 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
  38. 'DEFAULT_AUTHENTICATION_CLASSES': ['common.auth.authenticate.AnonymousAuthentication']
  39. }
  40. STATICFILES_DIRS = [(os.path.join(PROJECT_DIR, 'ui', 'dist'))]
  41. STATIC_ROOT = os.path.join(BASE_DIR.parent, 'static')
  42. ROOT_URLCONF = 'maxkb.urls'
  43. APPS_DIR = os.path.join(PROJECT_DIR, 'apps')
  44. TEMPLATES = [
  45. {
  46. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  47. 'DIRS': ["apps/static/admin"],
  48. 'APP_DIRS': True,
  49. 'OPTIONS': {
  50. 'context_processors': [
  51. 'django.template.context_processors.debug',
  52. 'django.template.context_processors.request',
  53. 'django.contrib.auth.context_processors.auth',
  54. 'django.contrib.messages.context_processors.messages',
  55. ],
  56. },
  57. },
  58. {"NAME": "CHAT",
  59. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  60. 'DIRS': ["apps/static/chat"],
  61. 'APP_DIRS': True,
  62. 'OPTIONS': {
  63. 'context_processors': [
  64. 'django.template.context_processors.debug',
  65. 'django.template.context_processors.request',
  66. 'django.contrib.auth.context_processors.auth',
  67. 'django.contrib.messages.context_processors.messages',
  68. ],
  69. },
  70. },
  71. {"NAME": "DOC",
  72. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  73. 'DIRS': ["apps/static/drf_spectacular_sidecar"],
  74. 'APP_DIRS': True,
  75. 'OPTIONS': {
  76. 'context_processors': [
  77. 'django.template.context_processors.debug',
  78. 'django.template.context_processors.request',
  79. 'django.contrib.auth.context_processors.auth',
  80. 'django.contrib.messages.context_processors.messages',
  81. ],
  82. },
  83. },
  84. ]
  85. SPECTACULAR_SETTINGS = {
  86. 'TITLE': '网讯智能体平台 API',
  87. 'DESCRIPTION': _('Intelligent customer service platform'),
  88. 'VERSION': 'v2',
  89. 'SERVE_INCLUDE_SCHEMA': False,
  90. # OTHER SETTINGS
  91. 'SWAGGER_UI_DIST': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist', # shorthand to use the sidecar instead
  92. 'SWAGGER_UI_FAVICON_HREF': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist/favicon-32x32.png',
  93. 'REDOC_DIST': f'{CONFIG.get_admin_path()}/api-doc/redoc',
  94. 'SECURITY_DEFINITIONS': {
  95. 'Bearer': {
  96. 'type': 'apiKey',
  97. 'name': 'AUTHORIZATION',
  98. 'in': 'header',
  99. }
  100. }
  101. }
  102. WSGI_APPLICATION = 'maxkb.wsgi.application'
  103. # Database
  104. # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
  105. DATABASES = {'default': CONFIG.get_db_setting()}
  106. CACHES = CONFIG.get_cache_setting()
  107. # Password validation
  108. # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
  109. AUTH_PASSWORD_VALIDATORS = [
  110. {
  111. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  112. },
  113. {
  114. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  115. },
  116. {
  117. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  118. },
  119. {
  120. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  121. },
  122. ]
  123. # Internationalization
  124. # https://docs.djangoproject.com/en/4.2/topics/i18n/
  125. LANGUAGE_CODE = CONFIG.get("LANGUAGE_CODE")
  126. TIME_ZONE = CONFIG.get_time_zone()
  127. USE_I18N = True
  128. USE_TZ = True
  129. # 文件上传配置
  130. DATA_UPLOAD_MAX_NUMBER_FILES = 1000
  131. # 支持的语言
  132. LANGUAGES = [
  133. ('en', 'English'),
  134. ('zh', '中文简体'),
  135. ('zh-hant', '中文繁体')
  136. ]
  137. # 翻译文件路径
  138. LOCALE_PATHS = [
  139. os.path.join(BASE_DIR.parent, 'locales')
  140. ]
  141. # Static files (CSS, JavaScript, Images)
  142. # https://docs.djangoproject.com/en/4.2/howto/static-files/
  143. STATIC_URL = 'static/'
  144. # Default primary key field type
  145. # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
  146. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  147. edition = 'CE'
  148. if os.environ.get('MAXKB_REDIS_SENTINEL_SENTINELS') is not None:
  149. DJANGO_REDIS_CONNECTION_FACTORY = "django_redis.pool.SentinelConnectionFactory"