""" Django settings for core project. Generated by 'django-admin startproject' using Django 5.1.7. For more information on this file, see https://docs.djangoproject.com/en/5.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.1/ref/settings/ """ from pathlib import Path from scheduler.types import SchedulerConfiguration import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", 'django-insecure-54mqLbW5NlO8OlVDsT3fcbg3Vf6C8Fgcoj8H0hXv3Pr8bpgqvOuiaeqvGn34sGwt') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = (os.environ.get('DJANGO_DEBUG') == "True") ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', "*").split(",") CSRF_TRUSTED_ORIGINS = os.environ.get('DJANGO_ALLOWED_ORIGINS', "*").split(",") #CSRF_TRUSTED_ORIGINS = ["https://fetcher.matitos.org"] #CSRF_ALLOWED_ORIGINS = ["https://fetcher.matitos.org"] #CORS_ORIGINS_WHITELIST = ["https://fetcher.matitos.org"] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'scheduler', 'fetcher', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', # Serving static files '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', 'fetcher.middleware.login_required.LoginRequiredMiddleware', ] STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' ROOT_URLCONF = 'core.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], '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 = 'core.wsgi.application' # Database DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ.get("DB_NAME", "matitos"), 'USER': os.environ.get("DB_USER", "supermatitos"), 'PASSWORD': os.environ.get("DB_PASSWORD", "supermatitos"), 'HOST': os.environ.get("DB_HOST", "localhost"), 'PORT': os.environ.get("DB_PORT", "5432"), #'OPTIONS': { # 'options': '-c default_transaction_read_only=on' #} } } CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://{}:{}".format( os.environ.get("REDIS_HOST", "localhost"), os.environ.get("REDIS_PORT", 6379) ), "OPTIONS": { "MEMCACHE_MAX_KEY_LENGTH": 2048, "CLIENT_CLASS": "django_redis.client.DefaultClient", }, } } # https://django-tasks-scheduler.readthedocs.io/en/latest/configuration/ SCHEDULER_QUEUES = { 'default': { 'HOST': os.environ.get("REDIS_HOST", "localhost"), 'PORT': os.environ.get("REDIS_PORT", 6379), 'DB': os.environ.get("REDIS_DB", 0), }, 'high': { 'HOST': os.environ.get("REDIS_HOST", "localhost"), 'PORT': os.environ.get("REDIS_PORT", 6379), 'DB': os.environ.get("REDIS_DB", 0), }, 'low': { 'HOST': os.environ.get("REDIS_HOST", "localhost"), 'PORT': os.environ.get("REDIS_PORT", 6379), 'DB': os.environ.get("REDIS_DB", 0), } } SCHEDULER_CONFIG = SchedulerConfiguration( 'DEFAULT_JOB_TIMEOUT': os.environ.get("JOB_DEFAULT_TIMEOUT", 60*30), # 30 minutes ) # Password validation 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', }, ] LOGIN_URL = '/admin/' # Internationalization LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') # Default primary key field type DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'