2024-07-08 11:44:39 -04:00
"""
Django settings for demo project .
For more information on this file , see
https : / / docs . djangoproject . com / en / 1.7 / topics / settings /
For the full list of settings and their values , see
https : / / docs . djangoproject . com / en / 1.7 / ref / settings /
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from dotenv import load_dotenv
from os import getenv
2024-07-09 09:58:52 -04:00
from pathlib import Path
2025-01-14 09:38:38 -05:00
from urllib . parse import urlparse
2025-01-26 20:06:47 -05:00
from publicsuffix2 import get_sld
2024-07-08 11:44:39 -04:00
# Load environment variables from .env file
load_dotenv ( )
BASE_DIR = os . path . dirname ( os . path . dirname ( __file__ ) )
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = getenv ( ' SECRET_KEY ' )
# SECURITY WARNING: don't run with debug turned on in production!
2025-04-26 23:21:23 +02:00
DEBUG = getenv ( ' DEBUG ' , ' true ' ) . lower ( ) == ' true '
2024-07-08 11:44:39 -04:00
# ALLOWED_HOSTS = [
# 'localhost',
# '127.0.0.1',
# 'server'
# ]
ALLOWED_HOSTS = [ ' * ' ]
INSTALLED_APPS = (
' django.contrib.admin ' ,
' django.contrib.auth ' ,
' django.contrib.contenttypes ' ,
' django.contrib.sessions ' ,
' django.contrib.messages ' ,
' django.contrib.staticfiles ' ,
' django.contrib.sites ' ,
2025-01-07 10:27:11 -05:00
# "allauth_ui",
2024-07-08 11:44:39 -04:00
' rest_framework ' ,
' rest_framework.authtoken ' ,
' allauth ' ,
' allauth.account ' ,
2024-12-12 15:45:19 -05:00
' allauth.mfa ' ,
2024-11-29 14:41:13 -05:00
' allauth.headless ' ,
2024-07-08 11:44:39 -04:00
' allauth.socialaccount ' ,
2025-01-06 14:25:57 -05:00
' allauth.socialaccount.providers.github ' ,
' allauth.socialaccount.providers.openid_connect ' ,
2024-07-08 11:44:39 -04:00
' drf_yasg ' ,
' corsheaders ' ,
' adventures ' ,
' worldtravel ' ,
' users ' ,
2024-12-31 10:38:15 -05:00
' integrations ' ,
2024-08-23 13:56:27 -04:00
' django.contrib.gis ' ,
2025-02-15 19:44:11 -05:00
# 'achievements', # Not done yet, will be added later in a future update
2025-01-07 10:27:11 -05:00
# 'widget_tweaks',
# 'slippers',
2025-01-06 14:25:57 -05:00
2024-07-08 11:44:39 -04:00
)
MIDDLEWARE = (
2024-07-09 09:58:52 -04:00
' whitenoise.middleware.WhiteNoiseMiddleware ' ,
2025-02-23 17:04:20 -05:00
' adventures.middleware.XSessionTokenMiddleware ' ,
' adventures.middleware.DisableCSRFForSessionTokenMiddleware ' ,
2025-05-12 10:42:26 -04:00
' adventures.middleware.DisableCSRFForMobileLoginSignup ' ,
2024-07-08 11:44:39 -04:00
' corsheaders.middleware.CorsMiddleware ' ,
' django.contrib.sessions.middleware.SessionMiddleware ' ,
' django.middleware.common.CommonMiddleware ' ,
2025-01-06 20:44:37 -05:00
' adventures.middleware.OverrideHostMiddleware ' ,
2024-07-08 11:44:39 -04:00
' django.middleware.csrf.CsrfViewMiddleware ' ,
' django.contrib.auth.middleware.AuthenticationMiddleware ' ,
' django.contrib.messages.middleware.MessageMiddleware ' ,
' django.middleware.clickjacking.XFrameOptionsMiddleware ' ,
' allauth.account.middleware.AccountMiddleware ' ,
)
2024-08-04 21:50:15 -04:00
# disable verifications for new users
ACCOUNT_EMAIL_VERIFICATION = ' none '
2024-08-21 09:48:47 -04:00
CACHES = {
' default ' : {
' BACKEND ' : ' django.core.cache.backends.locmem.LocMemCache ' ,
}
}
2024-07-08 11:44:39 -04:00
# For backwards compatibility for Django 1.8
MIDDLEWARE_CLASSES = MIDDLEWARE
2024-07-20 21:39:33 -04:00
ROOT_URLCONF = ' main.urls '
2024-07-08 11:44:39 -04:00
# WSGI_APPLICATION = 'demo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
' default ' : {
2024-08-23 13:56:27 -04:00
' ENGINE ' : ' django.contrib.gis.db.backends.postgis ' ,
2025-05-26 16:55:00 -04:00
' NAME ' : getenv ( ' PGDATABASE ' ) or getenv ( ' POSTGRES_DB ' ) ,
' USER ' : getenv ( ' PGUSER ' ) or getenv ( ' POSTGRES_USER ' ) ,
' PASSWORD ' : getenv ( ' PGPASSWORD ' ) or getenv ( ' POSTGRES_PASSWORD ' ) ,
2024-07-08 11:44:39 -04:00
' HOST ' : getenv ( ' PGHOST ' ) ,
' PORT ' : getenv ( ' PGPORT ' , 5432 ) ,
' OPTIONS ' : {
' sslmode ' : ' prefer ' , # Prefer SSL, but allow non-SSL connections
} ,
}
}
2024-11-30 10:24:27 -05:00
2024-07-08 11:44:39 -04:00
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = ' en-us '
2024-08-17 08:30:24 -04:00
TIME_ZONE = ' UTC '
2024-07-08 11:44:39 -04:00
USE_I18N = True
USE_L10N = True
USE_TZ = True
2025-01-27 09:23:48 -05:00
unParsedFrontenedUrl = getenv ( ' FRONTEND_URL ' , ' http://localhost:3000 ' )
2025-02-01 15:10:25 -05:00
FRONTEND_URL = unParsedFrontenedUrl . translate ( str . maketrans ( ' ' , ' ' , ' \' " ' ) )
2025-01-14 09:38:38 -05:00
2025-02-16 15:35:10 -05:00
SESSION_COOKIE_SAMESITE = ' Lax '
2025-01-13 17:52:25 -05:00
2025-02-23 17:04:20 -05:00
SESSION_COOKIE_NAME = ' sessionid '
2025-01-14 09:38:38 -05:00
SESSION_COOKIE_SECURE = FRONTEND_URL . startswith ( ' https ' )
2025-02-20 10:21:48 -05:00
hostname = urlparse ( FRONTEND_URL ) . hostname
2025-01-14 09:38:38 -05:00
is_ip_address = hostname . replace ( ' . ' , ' ' ) . isdigit ( )
2025-01-26 20:06:47 -05:00
2025-02-20 10:21:48 -05:00
# Check if the hostname is single-label (no dots)
is_single_label = ' . ' not in hostname
if is_ip_address or is_single_label :
# Do not set a domain for IP addresses or single-label hostnames
2025-01-14 09:38:38 -05:00
SESSION_COOKIE_DOMAIN = None
else :
2025-01-26 20:06:47 -05:00
# Use publicsuffix2 to calculate the correct cookie domain
cookie_domain = get_sld ( hostname )
if cookie_domain :
SESSION_COOKIE_DOMAIN = f " . { cookie_domain } "
else :
# Fallback to the hostname if parsing fails
SESSION_COOKIE_DOMAIN = hostname
2025-02-20 10:21:48 -05:00
2024-07-08 11:44:39 -04:00
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
2025-01-13 19:21:35 -05:00
SECURE_PROXY_SSL_HEADER = ( ' HTTP_X_FORWARDED_PROTO ' , ' https ' )
2024-07-09 09:58:52 -04:00
BASE_DIR = Path ( __file__ ) . resolve ( ) . parent . parent
2024-11-05 10:15:38 -05:00
STATIC_ROOT = BASE_DIR / " staticfiles "
2024-07-08 11:44:39 -04:00
STATIC_URL = ' /static/ '
2024-07-09 09:58:52 -04:00
2024-07-08 11:44:39 -04:00
MEDIA_URL = ' /media/ '
2025-01-18 17:03:03 -05:00
MEDIA_ROOT = BASE_DIR / ' media ' # This path must match the NGINX root
2024-11-05 10:55:06 -05:00
STATICFILES_DIRS = [ BASE_DIR / ' static ' ]
2024-07-08 11:44:39 -04:00
2024-11-30 10:24:27 -05:00
STORAGES = {
" staticfiles " : {
" BACKEND " : " whitenoise.storage.CompressedManifestStaticFilesStorage " ,
} ,
" default " : {
" BACKEND " : " django.core.files.storage.FileSystemStorage " ,
}
}
2025-01-06 14:25:57 -05:00
SILENCED_SYSTEM_CHECKS = [ " slippers.E001 " ]
2024-11-30 10:24:27 -05:00
2024-07-08 11:44:39 -04:00
TEMPLATES = [
{
' BACKEND ' : ' django.template.backends.django.DjangoTemplates ' ,
' DIRS ' : [ os . path . join ( 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 ' ,
] ,
} ,
} ,
]
2024-11-30 10:24:27 -05:00
# Authentication settings
2025-04-26 23:21:23 +02:00
DISABLE_REGISTRATION = getenv ( ' DISABLE_REGISTRATION ' , ' false ' ) . lower ( ) == ' true '
2024-08-24 23:20:50 -04:00
DISABLE_REGISTRATION_MESSAGE = getenv ( ' DISABLE_REGISTRATION_MESSAGE ' , ' Registration is disabled. Please contact the administrator if you need an account. ' )
2024-08-16 10:59:31 -04:00
2024-07-08 11:44:39 -04:00
AUTH_USER_MODEL = ' users.CustomUser '
2024-11-29 14:41:13 -05:00
ACCOUNT_ADAPTER = ' users.adapters.NoNewUsersAccountAdapter '
2024-11-30 10:24:27 -05:00
ACCOUNT_SIGNUP_FORM_CLASS = ' users.form_overrides.CustomSignupForm '
SESSION_SAVE_EVERY_REQUEST = True
2025-01-06 14:25:57 -05:00
# Set login redirect URL to the frontend
LOGIN_REDIRECT_URL = FRONTEND_URL
2025-01-07 09:58:39 -05:00
SOCIALACCOUNT_LOGIN_ON_GET = True
2024-12-12 11:01:09 -05:00
HEADLESS_FRONTEND_URLS = {
" account_confirm_email " : f " { FRONTEND_URL } /user/verify-email/ {{ key }} " ,
" account_reset_password " : f " { FRONTEND_URL } /user/reset-password " ,
" account_reset_password_from_key " : f " { FRONTEND_URL } /user/reset-password/ {{ key }} " ,
" account_signup " : f " { FRONTEND_URL } /signup " ,
# Fallback in case the state containing the `next` URL is lost and the handshake
# with the third-party provider fails.
" socialaccount_login_error " : f " { FRONTEND_URL } /account/provider/callback " ,
}
2024-11-29 14:41:13 -05:00
2025-03-16 21:49:00 -04:00
AUTHENTICATION_BACKENDS = [
' users.backends.NoPasswordAuthBackend ' ,
]
2024-07-08 11:44:39 -04:00
EMAIL_BACKEND = ' django.core.mail.backends.console.EmailBackend '
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = ' username '
ACCOUNT_EMAIL_VERIFICATION = ' optional '
2024-08-04 18:05:19 -04:00
if getenv ( ' EMAIL_BACKEND ' , ' console ' ) == ' console ' :
EMAIL_BACKEND = ' django.core.mail.backends.console.EmailBackend '
else :
EMAIL_BACKEND = ' django.core.mail.backends.smtp.EmailBackend '
EMAIL_HOST = getenv ( ' EMAIL_HOST ' )
2025-04-26 23:21:23 +02:00
EMAIL_USE_TLS = getenv ( ' EMAIL_USE_TLS ' , ' true ' ) . lower ( ) == ' true '
2024-08-04 18:05:19 -04:00
EMAIL_PORT = getenv ( ' EMAIL_PORT ' , 587 )
2025-04-26 23:21:23 +02:00
EMAIL_USE_SSL = getenv ( ' EMAIL_USE_SSL ' , ' false ' ) . lower ( ) == ' true '
2024-08-04 18:05:19 -04:00
EMAIL_HOST_USER = getenv ( ' EMAIL_HOST_USER ' )
EMAIL_HOST_PASSWORD = getenv ( ' EMAIL_HOST_PASSWORD ' )
DEFAULT_FROM_EMAIL = getenv ( ' DEFAULT_FROM_EMAIL ' )
2024-07-08 11:44:39 -04:00
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_HOST = 'smtp.resend.com'
# EMAIL_USE_TLS = False
# EMAIL_PORT = 2465
# EMAIL_USE_SSL = True
# EMAIL_HOST_USER = 'resend'
# EMAIL_HOST_PASSWORD = ''
# DEFAULT_FROM_EMAIL = 'mail@mail.user.com'
REST_FRAMEWORK = {
' DEFAULT_AUTHENTICATION_CLASSES ' : (
' rest_framework.authentication.SessionAuthentication ' ,
) ,
' DEFAULT_SCHEMA_CLASS ' : ' rest_framework.schemas.coreapi.AutoSchema ' ,
}
2025-01-03 16:29:39 -05:00
if DEBUG :
REST_FRAMEWORK [ ' DEFAULT_RENDERER_CLASSES ' ] = (
' rest_framework.renderers.JSONRenderer ' ,
' rest_framework.renderers.BrowsableAPIRenderer ' ,
)
else :
REST_FRAMEWORK [ ' DEFAULT_RENDERER_CLASSES ' ] = (
' rest_framework.renderers.JSONRenderer ' ,
)
2024-11-29 14:41:13 -05:00
CORS_ALLOWED_ORIGINS = [ origin . strip ( ) for origin in getenv ( ' CSRF_TRUSTED_ORIGINS ' , ' http://localhost ' ) . split ( ' , ' ) if origin . strip ( ) ]
2024-07-10 11:34:19 -04:00
CSRF_TRUSTED_ORIGINS = [ origin . strip ( ) for origin in getenv ( ' CSRF_TRUSTED_ORIGINS ' , ' http://localhost ' ) . split ( ' , ' ) if origin . strip ( ) ]
2024-11-29 14:41:13 -05:00
2024-07-08 11:44:39 -04:00
DEFAULT_AUTO_FIELD = ' django.db.models.AutoField '
2024-08-21 09:48:47 -04:00
LOGGING = {
' version ' : 1 ,
' disable_existing_loggers ' : False ,
' handlers ' : {
' console ' : {
' class ' : ' logging.StreamHandler ' ,
} ,
' file ' : {
' class ' : ' logging.FileHandler ' ,
' filename ' : ' scheduler.log ' ,
} ,
} ,
' root ' : {
' handlers ' : [ ' console ' , ' file ' ] ,
' level ' : ' INFO ' ,
} ,
' loggers ' : {
' django ' : {
' handlers ' : [ ' console ' , ' file ' ] ,
' level ' : ' INFO ' ,
' propagate ' : False ,
} ,
} ,
2024-09-11 16:08:10 -04:00
}
2025-02-04 17:43:41 -05:00
2025-02-15 19:44:11 -05:00
# ADVENTURELOG_CDN_URL = getenv('ADVENTURELOG_CDN_URL', 'https://cdn.adventurelog.app')
# https://github.com/dr5hn/countries-states-cities-database/tags
2025-05-22 21:22:27 -04:00
COUNTRY_REGION_JSON_VERSION = ' v2.6 '
2025-05-24 14:59:58 -04:00
GOOGLE_MAPS_API_KEY = getenv ( ' GOOGLE_MAPS_API_KEY ' , ' ' )