settings.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. """
  2. Django settings for mserv00 project.
  3. Generated by 'django-admin startproject' using Django 5.2.3.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/5.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/5.2/ref/settings/
  8. """
  9. import os
  10. from pathlib import Path
  11. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  12. BASE_DIR = Path(__file__).resolve().parent.parent
  13. # Quick-start development settings - unsuitable for production
  14. # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
  15. # SECURITY WARNING: keep the secret key used in production secret!
  16. SECRET_KEY = 'django-insecure-89&_=swo6&=@z714%#k6oo$ayu-cn5yu9k@h$+bq^=kf$#f!c3'
  17. # SECURITY WARNING: don't run with debug turned on in production!
  18. DEBUG = True
  19. # Base hosts always allowed
  20. _ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'host.docker.internal']
  21. # Accept extra hosts from env (comma-separated), e.g. machine hostname or IP
  22. _extra = os.getenv('DJANGO_ALLOWED_HOSTS', '')
  23. if _extra:
  24. _ALLOWED_HOSTS += [h.strip() for h in _extra.split(',') if h.strip()]
  25. ALLOWED_HOSTS = _ALLOWED_HOSTS
  26. # Application definition
  27. INSTALLED_APPS = [
  28. 'django.contrib.admin',
  29. 'django.contrib.auth',
  30. 'django.contrib.contenttypes',
  31. 'django.contrib.sessions',
  32. 'django.contrib.messages',
  33. 'django.contrib.staticfiles',
  34. 'rest_framework',
  35. 'django_filters',
  36. 'spectrometer'
  37. ]
  38. MIDDLEWARE = [
  39. 'django.middleware.security.SecurityMiddleware',
  40. 'django.contrib.sessions.middleware.SessionMiddleware',
  41. 'django.middleware.common.CommonMiddleware',
  42. 'django.middleware.csrf.CsrfViewMiddleware',
  43. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  44. 'django.contrib.messages.middleware.MessageMiddleware',
  45. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  46. ]
  47. ROOT_URLCONF = 'mserv00.urls'
  48. TEMPLATES = [
  49. {
  50. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  51. 'DIRS': [],
  52. 'APP_DIRS': True,
  53. 'OPTIONS': {
  54. 'context_processors': [
  55. 'django.template.context_processors.request',
  56. 'django.contrib.auth.context_processors.auth',
  57. 'django.contrib.messages.context_processors.messages',
  58. ],
  59. },
  60. },
  61. ]
  62. WSGI_APPLICATION = 'mserv00.wsgi.application'
  63. # Database
  64. # https://docs.djangoproject.com/en/5.2/ref/settings/#databases
  65. if os.getenv('USE_POSTGRES', '').lower() in {'1', 'true', 'yes'}:
  66. DATABASES = {
  67. 'default': {
  68. 'ENGINE': 'django.db.backends.postgresql',
  69. 'NAME': os.getenv('POSTGRES_DB', 'specdata'),
  70. 'USER': os.getenv('POSTGRES_USER', 'specadmin'),
  71. 'PASSWORD': os.getenv('POSTGRES_PASSWORD', 'specadmin'),
  72. 'HOST': os.getenv('POSTGRES_HOST', 'localhost'),
  73. 'PORT': os.getenv('POSTGRES_PORT', '5432'),
  74. }
  75. }
  76. else:
  77. DATABASES = {
  78. 'default': {
  79. 'ENGINE': 'django.db.backends.sqlite3',
  80. 'NAME': BASE_DIR / 'db.sqlite3',
  81. }
  82. }
  83. # Password validation
  84. # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
  85. AUTH_PASSWORD_VALIDATORS = [
  86. {
  87. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  88. },
  89. {
  90. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  91. },
  92. {
  93. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  94. },
  95. {
  96. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  97. },
  98. ]
  99. REST_FRAMEWORK = {
  100. 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
  101. 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
  102. 'PAGE_SIZE': 10,
  103. # No authentication required -- local lab device, not exposed to internet
  104. 'DEFAULT_AUTHENTICATION_CLASSES': [],
  105. 'DEFAULT_PERMISSION_CLASSES': ['rest_framework.permissions.AllowAny'],
  106. }
  107. # Internationalization
  108. # https://docs.djangoproject.com/en/5.2/topics/i18n/
  109. LANGUAGE_CODE = 'ru-ru'
  110. TIME_ZONE = 'Europe/Moscow'
  111. USE_I18N = True
  112. USE_TZ = True
  113. # Static files (CSS, JavaScript, Images)
  114. # https://docs.djangoproject.com/en/5.2/howto/static-files/
  115. STATIC_URL = 'static/'
  116. STATIC_ROOT = BASE_DIR / 'static'
  117. # Default primary key field type
  118. # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
  119. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'