right-tree/backend/right_tree/settings.py
2023-03-06 18:10:25 +13:00

167 lines
4.5 KiB
Python

"""
Django settings for right_tree project.
Generated by 'django-admin startproject' using Django 3.2.8.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
import stripe
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
BASE_URL = os.getenv("BASE_URL", "localhost:8000")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", 'django-insecure-5t05qc2&14xuot4lgs#z0ll9(nn-=3-8yks!u(5ce704t&m_*q')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DJANGO_DEBUG_MODE', '') != 'False'
# os.getenv("ALLOWED_HOSTS", "").split(","),
ALLOWED_HOSTS = [BASE_URL, "localhost"]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'rest_framework',
'corsheaders',
'right_tree.api',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
'corsheaders.middleware.CorsMiddleware',
]
ROOT_URLCONF = 'right_tree.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 = 'right_tree.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
db = {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': os.getenv("DATABASE_NAME", "righttree"),
'USER': os.getenv("DATABASE_USER", "righttree"),
'PASSWORD': os.getenv("DATABASE_PASSWORD", "righttree"),
'HOST': os.getenv("DATABASE_HOST", "postgres"),
'PORT': int(os.getenv("DATABASE_PORT", 5432)),
}
DATABASES = {
'default': db,
'linz': {
**db,
'OPTIONS': {
'options': '-c search_path=linz'
},
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Pacific/Auckland'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/staticfiles/'
PROJECT_DIR = Path(os.path.abspath(__file__)).parent
STATIC_ROOT = PROJECT_DIR / 'staticfiles'
MEDIA_ROOT = PROJECT_DIR / 'media'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CORS_ALLOW_HEADERS = [
'access-control-allow-origin'
]
# Redis configuration
REDIS_HOST = os.getenv("REDIS_HOST", "redis")
REDIS_PORT = int(os.getenv("REDIS_PORT", 6379))
REDIS_PASSWORD = os.getenv("REDIS_PASSWORD", "redis")
REDIS_BASE_URL = f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}"
REDIS_CELERY_URL = REDIS_BASE_URL + "/0"
REDIS_DJANGO_URL = REDIS_BASE_URL + "/1"
# Celery configuration
CELERY_TIMEZONE = TIME_ZONE
CELERY_BROKER_URL = REDIS_CELERY_URL
# Stripe payment processing
stripe.api_key = os.environ['STRIPE_API_KEY']