def process_input(original_list, input_list):
# 创建原始列表的深拷贝以便修改
current_list = [dict(obj) for obj in original_list]
for input_obj in input_list:
prefix = input_obj['prefix']
# 查找对应的原始对象
found_index = -1
for idx, obj in enumerate(current_list):
if obj['prefix'] == prefix:
found_index = idx
break
if found_index == -1:
continue # 没有对应的prefix,跳过
original_obj = current_list[found_index]
s1 = int(original_obj['start'])
e1 = int(original_obj['end'])
s2 = int(input_obj['start'])
e2 = int(input_obj['end'])
# 计算交集
intersect_start = max(s1, s2)
intersect_end = min(e1, e2)
if intersect_start >= intersect_end:
continue # 无交集,跳过
# 处理交集
if intersect_start == s1 and intersect_end == e1:
# 完全覆盖,删除原始对象
del current_list[found_index]
elif intersect_start == s1:
# 交集从原始对象的起始开始,调整起始值
original_obj['start'] = str(intersect_end)
elif intersect_end == e1:
# 交集到原始对象的结束为止,调整结束值
original_obj['end'] = str(intersect_start)
else:
# 交集在中间,无法处理,直接删除原始对象
del current_list[found_index]
# 检查调整后的start和end是否有效
if found_index < len(current_list) and int(current_list[found_index]['start']) >= int(current_list[found_index]['end']):
del current_list[found_index]
return current_list if current_list else []
base.py
"""
Base settings to build other settings files upon.
"""
from pathlib import Path
from backend.gnsuser.gnsuser import GnsuserAPI
import environ
import os
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
# backend/
APPS_DIR = BASE_DIR / "backend"
env = environ.Env()
# READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
# if READ_DOT_ENV_FILE:
# OS environment variables take precedence over variables from .env
# env.read_env(str(BASE_DIR / ".env"))
mode = os.getenv('MODE','local')
print(f"开发模式:{mode}")
if mode == "local":
env.read_env("/home/chf/gns_objs/cews/backend/.envs/.local/.django")
env.read_env("/home/chf/gns_objs/cews/backend/.envs/.local/.mongo")
env.read_env("/home/chf/gns_objs/cews/backend/.envs/.local/.postgres")
# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool("DJANGO_DEBUG", False)
# Local time zone. Choices are
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# though not all of them may be available with every OS.
# In Windows, this must be set to your system time zone.
TIME_ZONE = "Asia/Hong_Kong"
# https://docs.djangoproject.com/en/dev/ref/settings/#language-code
LANGUAGE_CODE = "zh-hans"
# https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True
# https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True
# https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths
LOCALE_PATHS = [str(BASE_DIR / "locale")]
# DATABASES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
"default": env.db("DATABASE_URL"),
# "iosystem": "postgres://debug:sorAtpXZRKlW9GDRamu3w@192.168.1.2:5432/mtr_qr",
"iosystem": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "mtr_qr",
"USER": "inhouse",
"PASSWORD": "12345678",
"HOST": "192.168.1.2",
"PORT": "5432",
},
"mongo": {
"ENGINE": "djongo",
"NAME": str(env('MONGO_DATABASE_NAME')),
"CLIENT": {
"USERNAME": str(env('MONGO_INITDB_ROOT_USERNAME')),
"PASSWORD": str(env('MONGO_INITDB_ROOT_PASSWORD')),
"host": str(env('MONGO_HOST')),
"port": int(env('MONGO_PORT')),
# 'authSource': str(env('DATABASE_AUTHSOURCE')),
# 'AUTHMECHANISM': 'SCRAM-SHA-256',
},
'OPTIONS': {
'socketTimeoutMS': 500,
# if you using timezones in django (USE_TZ = True)
"tz_aware": True,
}
},
}
print(f"数据库连接: {DATABASES}")
DATABASES["default"]["ATOMIC_REQUESTS"] = True
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
# URLS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
ROOT_URLCONF = "config.urls"
# https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = "config.wsgi.application"
# APPS
# ------------------------------------------------------------------------------
DJANGO_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
# "django.contrib.humanize", # Handy template tags
"django.contrib.admin",
"django.forms",
]
THIRD_PARTY_APPS = [
"crispy_forms",
"crispy_bootstrap5",
"allauth",
"allauth.account",
"allauth.socialaccount",
"django_celery_beat",
"rest_framework",
"rest_framework.authtoken",
"django_celery_results",
"corsheaders",
"drf_spectacular",
"qr_code",
"sslserver"
]
LOCAL_APPS = [
"backend.users",
"backend.cews",
"backend.maintenance",
"backend.eform",
"backend.eformConvert",
"backend.gnsuser",
"django_filters"
# Your stuff: custom apps go here
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# MIGRATIONS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules
MIGRATION_MODULES = {"sites": "backend.contrib.sites.migrations"}
# AUTHENTICATION
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
AUTH_USER_MODEL = "users.User"
# https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
LOGIN_REDIRECT_URL = "users:redirect"
# https://docs.djangoproject.com/en/dev/ref/settings/#login-url
LOGIN_URL = "account_login"
# PASSWORDS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers
PASSWORD_HASHERS = [
# https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
]
# https://docs.djangoproject.com/en/dev/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"},
]
# MIDDLEWARE
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"corsheaders.middleware.CorsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"backend.users.middleware.SessionCookieAgeMiddleware"
]
# STATIC
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(BASE_DIR / "staticfiles")
# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = "/static/"
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [str(APPS_DIR / "static")]
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
# MEDIA
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR / "media")
# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = "/media/"
# TEMPLATES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
TEMPLATES = [
{
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
"BACKEND": "django.template.backends.django.DjangoTemplates",
# https://docs.djangoproject.com/en/dev/ref/settings/#dirs
"DIRS": [str(APPS_DIR / "templates")],
# https://docs.djangoproject.com/en/dev/ref/settings/#app-dirs
"APP_DIRS": True,
"OPTIONS": {
# https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"backend.users.context_processors.allauth_settings",
],
},
}
]
# https://docs.djangoproject.com/en/dev/ref/settings/#form-renderer
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
# http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = "bootstrap5"
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
# FIXTURES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#fixture-dirs
FIXTURE_DIRS = (str(APPS_DIR / "fixtures"),)
# SECURITY
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
SESSION_COOKIE_HTTPONLY = env.bool("SESSION_COOKIE_HTTPONLY", default=True)
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
CSRF_COOKIE_HTTPONLY = env.bool("CSRF_COOKIE_HTTPONLY", default=True)
# https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
X_FRAME_OPTIONS = "DENY"
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend",
# https://docs.djangoproject.com/en/dev/ref/settings/#email-timeout
EMAIL_TIMEOUT = 5
# ADMIN
# ------------------------------------------------------------------------------
# Django Admin URL.
ADMIN_URL = "admin/"
# https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = [("""gns""", "gns@example.com")]
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# LOGGING
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
# See https://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
}
},
"root": {"level": "INFO", "handlers": ["console"]},
}
# Celery
# ------------------------------------------------------------------------------
if USE_TZ:
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone
CELERY_TIMEZONE = TIME_ZONE
CELERY_WORKER_CONCURRENCY = 4 # 并发工作进程的数量, 降低内存
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend
CELERY_RESULT_BACKEND = "django-db"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended
CELERY_RESULT_EXTENDED = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-always-retry
# https://github.com/celery/celery/pull/6122
CELERY_RESULT_BACKEND_ALWAYS_RETRY = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-max-retries
CELERY_RESULT_BACKEND_MAX_RETRIES = 10
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-accept_content
CELERY_ACCEPT_CONTENT = ["json"]
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-task_serializer
CELERY_TASK_SERIALIZER = "json"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_serializer
CELERY_RESULT_SERIALIZER = "json"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-time-limit
# TODO: set to whatever value is adequate in your circumstances
CELERY_TASK_TIME_LIMIT = 5 * 60
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-soft-time-limit
# TODO: set to whatever value is adequate in your circumstances
CELERY_TASK_SOFT_TIME_LIMIT = 60
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#beat-scheduler
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#worker-send-task-events
CELERY_WORKER_SEND_TASK_EVENTS = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_send_sent_event
CELERY_TASK_SEND_SENT_EVENT = True
# test
CELERY_WORKER_CONCURRENCY = 4 # 并发工作进程的数量, 降低内存
CELERY_TASK_RESULT_EXPIRES = 3600
CELERY_RESULT_COMPRESSION = "gzip"
CELERY_WORKER_PREFETCH_MULTIPLIER = 1 # 预取任务的数量
# django-allauth
# ------------------------------------------------------------------------------
ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", False)
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_AUTHENTICATION_METHOD = "username"
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_EMAIL_REQUIRED = False
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_EMAIL_VERIFICATION = "optional"
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_ADAPTER = "backend.users.adapters.AccountAdapter"
# https://django-allauth.readthedocs.io/en/latest/forms.html
ACCOUNT_FORMS = {"signup": "backend.users.forms.UserSignupForm"}
# https://django-allauth.readthedocs.io/en/latest/configuration.html
SOCIALACCOUNT_ADAPTER = "backend.users.adapters.SocialAccountAdapter"
# https://django-allauth.readthedocs.io/en/latest/forms.html
SOCIALACCOUNT_FORMS = {"signup": "backend.users.forms.UserSocialSignupForm"}
# django-compressor
# ------------------------------------------------------------------------------
# https://django-compressor.readthedocs.io/en/latest/quickstart/#installation
INSTALLED_APPS += ["compressor"]
STATICFILES_FINDERS += ["compressor.finders.CompressorFinder"]
# django-rest-framework
# -------------------------------------------------------------------------------
# django-rest-framework - https://www.django-rest-framework.org/api-guide/settings/
REST_FRAMEWORK = {
"EXCEPTION_HANDLER": "backend.utils.custom_class.custom_exception_handler",
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.SessionAuthentication",
"backend.users.middleware.CustomTokenAuthentication",
# "rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup
# By Default swagger ui is available only to admin user(s). You can change permission classes to change that
# See more configuration options at https://drf-spectacular.readthedocs.io/en/latest/settings.html#settings
SPECTACULAR_SETTINGS = {
"TITLE": "backend API",
"DESCRIPTION": "Documentation of API endpoints of backend",
"VERSION": "1.0.0",
"SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"],
}
# Your stuff...
# ------------------------------------------------------------------------------
# CORS_URLS_REGEX = r'^/media/.*$'
# CORS_ALLOWED_ORIGIN_REGEXES = [
# r"^http://localhost:\d{1,4}$",
# r"^http://localhost$",
# r"^http://stage.cews.gnslocal:\d{1,4}$",
# r"^http://stage.cews.gnslocal$",
# r"^http://192.168.2.100:\d{1,4}$",
# r"^http://192.168.2.100$",
# r"^http://192.168.30.72:\d{1,4}$",
# r"^http://192.168.30.72$",
# ## public stage env
# r"^https://stage.cews.gnshk.com:\d{1,4}$",
# r"^https://stage.cews.gnshk.com$",
# r"^https://stage.cews.django.gnshk.com:\d{1,4}$",
# r"^https://stage.cews.django.gnshk.com$",
# r"^http://stage.cews.gnshk.com:\d{1,4}$",
# r"^http://stage.cews.gnshk.com$",
# r"^http://stage.cews.django.gnshk.com:\d{1,4}$",
# r"^http://stage.cews.django.gnshk.com$",
# ## prod
# r"^http://cews.gnshk.com:\d{1,4}$",
# r"^http://cews.gnshk.com$",
# r"^http://cews.django.gnshk.com:\d{1,4}$",
# r"^http://cews.django.gnshk.com$",
# r"^https://cews.gnshk.com:\d{1,4}$",
# r"^https://cews.gnshk.com$",
# r"^https://cews.django.gnshk.com:\d{1,4}$",
# r"^https://cews.django.gnshk.com$",
# ## prod
# r"^http://dms.cews.gnshk.com:\d{1,4}$",
# r"^http://dms.cews.gnshk.com$",
# r"^http://dms.cews.django.gnshk.com:\d{1,4}$",
# r"^http://dms.cews.django.gnshk.com$",
# r"^https://dms.cews.gnshk.com:\d{1,4}$",
# r"^https://dms.cews.gnshk.com$",
# r"^https://dms.cews.django.gnshk.com:\d{1,4}$",
# r"^https://dms.cews.django.gnshk.com$",
# #k8
# r"^http://10.100.11.2:30901$",
# r"^http://192.168.0.10:30901$",
# r"^http://10.28.0.30:30901$",
# r"^http://192.168.0.20:30901$",
# r"^http://10.28.0.33:30901$",
# r"^http://10.28.0.34:30901$",
# r"^http://10.28.0.30$",
# r"^http://10.28.0.31$",
# r"^http://192.168.0.2$",
# r"^http://192.168.0.3$",
# r"^http://192.168.1.155$",
# r"^http://10.28.0.2$",
# r"^https://cews.django.gnshk.com$",
# r"^https://cews.gnshk.com$",
# r"^https://frontend.chenhaifeng.top$",
# r"^https://backend.chenhaifeng.top$",
# ]
# CORS_ALLOW_HEADERS = [
# "Authorization",
# ]
DATABASE_ROUTERS = ['config.db_router.AppsRouter']
EFORM_DELETE_REDIRECT_URL = env('VUE_URL',default='http://localhost:9000')
## GNS USER
GNS_USER_DEBUG=env('GNS_USER_DEBUG',default='True') in ['True','true','TRUE']
## PASS DEBUG to True in developlment
GNS_USER_API = GnsuserAPI(DEBUG=False)
FILE_UPLOAD_MAX_MEMORY_SIZE = 10485760
# 限制可以在内存中缓存的请求体的最大大小为 10 MB
DATA_UPLOAD_MAX_MEMORY_SIZE = 10485760
# 登录时间限制 (分钟)
LOGIN_TIME_LIMIT = env.int('LOGIN_TIME_LIMIT', default=7 * 24 * 60)
# 活跃时间限制 (分钟)
ACTIVE_TIME_LIMIT = env.int('ACTIVE_TIME_LIMIT', default=24 * 60)
# 改成7天
CSRF_COOKIE_AGE = 60 * 60 * 24 * 7
local.py
from .base import * # noqa
from .base import env
# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = env(
"DJANGO_SECRET_KEY",
default="cmXDCy9xuAELXRrG70pSvTluNtfgTySCkUspXI9dgwayT65DSVNnPngl0XKzVfkC",
)
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
# ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1",'stage.cews.gnslocal','192.168.2.100','192.168.30.72','stage.cews.django.gnshk','stage.cews.gnshk']
ALLOWED_HOSTS = ["*"]
# CACHES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": env("REDIS_URL"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
# Mimicing memcache behavior.
# https://github.com/jazzband/django-redis#memcached-exceptions-behavior
"IGNORE_EXCEPTIONS": True,
},
}
}
# EMAIL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend")
# WhiteNoise
# ------------------------------------------------------------------------------
# http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development
INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS # noqa: F405
# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
# INSTALLED_APPS += ["debug_toolbar"] # noqa: F405
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
# MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa: F405
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
DEBUG_TOOLBAR_CONFIG = {
"DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
"SHOW_TEMPLATE_CONTEXT": True,
}
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
INTERNAL_IPS = ["127.0.0.1", "10.0.2.2"]
if env("USE_DOCKER") == "yes":
import socket
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS += [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips]
# django-extensions
# ------------------------------------------------------------------------------
# https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration
INSTALLED_APPS += ["django_extensions"] # noqa: F405
# Celery
# ------------------------------------------------------------------------------
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-eager-propagates
CELERY_TASK_EAGER_PROPAGATES = True
# Your stuff...
# ------------------------------------------------------------------------------
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
# CORS_ORIGIN_WHITELIST = (
# 'http://127.0.0.1:8080',
# )
CORS_ALLOWED_ORIGINS_REGEXES=[
r'^http://.*?$',
]
# CORS_ORIGIN_REGEXES_WHITELIST = (
# r'^http://.*?$',
# )
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'VIEW',
)
CORS_ALLOW_HEADERS = (
'XMLHttpRequest',
'X_FILENAME',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'Pragma',
)
stage.yml
version: '3'
volumes:
production_postgres_data: {}
production_postgres_data_backups: {}
production_traefik: {}
production_django_media: {}
production_django_static: {}
django_logs: {}
services:
django: &django
restart: always
build:
context: ./backend
dockerfile: ./compose/production/django/Dockerfile
image: backend_production_django
volumes:
- ./backend/backend/media:/app/backend/media
# - production_django_media:/app/backend/media
- production_django_static:/app/staticfiles
- django_logs:/app/logs
depends_on:
- postgres
- redis
ports:
- 5000:5000
env_file:
- ./backend/.envs/.production/.django
- ./backend/.envs/.production/.postgres
- ./backend/.envs/.production/.mongo
environment:
- DJANGO_DEBUG=True
- MODE="stage"
command: /start
postgres:
restart: always
build:
context: ./backend
dockerfile: ./compose/production/postgres/Dockerfile
image: backend_production_postgres
volumes:
- production_postgres_data:/var/lib/postgresql/data
- production_postgres_data_backups:/backups
env_file:
- ./backend/.envs/.production/.postgres
ports:
- "5432:5432"
redis:
image: redis:6
restart: always
ports:
- "6379:6379"
celeryworker:
<<: *django
image: backend_production_celeryworker
command: /start-celeryworker
ports: []
celerybeat:
<<: *django
image: backend_production_celerybeat
command: /start-celerybeat
ports: []
flower:
<<: *django
image: backend_production_flower
command: /start-flower
ports: []
mongo:
image: mongo
restart: always
env_file:
- ./backend/.envs/.production/.mongo
volumes:
- ./srv/mongodb:/data/db
ports:
- 27017:27017
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
env_file:
- ./backend/.envs/.production/.mongo
nginx:
image: gnstec/cews-nginx:latest
restart: always
build:
context: ./frontend
dockerfile: ./compose/stage/Dockerfile
volumes:
- production_django_static:/static
- ./backend/backend/media:/media
ports:
- "80:80"
- "8000:8000"
depends_on:
- django