Files
zod-backend/zod_bank/settings.py
2024-03-07 12:40:01 +05:30

337 lines
8.8 KiB
Python

"""
Django settings for ZOD_Bank project.
Generated by 'django-admin startproject' using Django 3.0.14.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
# Django Import
import os
from dotenv import load_dotenv
from datetime import timedelta
from firebase_admin import initialize_app
load_dotenv()
# OR, the same with increased verbosity:
load_dotenv(verbose=True)
# env path
env_path = os.path.join(os.path.abspath(os.path.join('.env', os.pardir)), '.env')
load_dotenv(dotenv_path=env_path)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# OR, the same with increased verbosity:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG')
ENV = os.getenv('ENV')
# cors allow setting
CORS_ORIGIN_ALLOW_ALL = False
# Allow specific origins
if ENV in ['dev', 'qa', 'stage']:
CORS_ALLOWED_ORIGINS = [
# backend base url
"https://dev-api.zodqaapp.com",
"https://qa-api.zodqaapp.com",
"https://stage-api.zodqaapp.com",
# frontend url
"http://localhost:3000",
"https://zod-dev.zodqaapp.com",
"https://zod-qa.zodqaapp.com",
"https://zod-stage.zodqaapp.com",
# Add more trusted origins as needed
]
if ENV == "prod":
CORS_ALLOWED_ORIGINS = [
# backend base url
"https://prod-api.zodbank.com",
# frontend url
"https://web.zodbank.com",
# Add more trusted origins as needed
]
# allow all host
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
# Add your installed Django apps here
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Add Django rest framework apps here
'django_extensions',
'storages',
'drf_yasg',
'corsheaders',
'django.contrib.postgres',
'rest_framework',
'fcm_django',
'django_celery_beat',
# Add your custom apps here.
'django_ses',
'account',
'junior',
'guardian',
'notifications',
'web_admin',
# 'social_django'
]
# define middle ware here
MIDDLEWARE = [
# Add your middleware classes here.
'corsheaders.middleware.CorsMiddleware',
'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',
'account.custom_middleware.CustomMiddleware'
]
# define root
ROOT_URLCONF = 'zod_bank.urls'
# define templates
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',
],
},
},
]
# define wsgi
WSGI_APPLICATION = 'zod_bank.wsgi.application'
# define rest frame work
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
# 'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
}
# define jwt token
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(hours=2, minutes=59, seconds=59, microseconds=999999),
'REFRESH_TOKEN_LIFETIME': timedelta(days=364, hours=23, minutes=59, seconds=59, microseconds=999999),
}
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
# default db setting
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME':os.getenv('DB_NAME'),
'USER':os.getenv('DB_USERNAME'),
'PASSWORD':os.getenv('DB_PASSWORD'),
'HOST':os.getenv('DB_HOST'),
'PORT':os.getenv('DB_PORT'),
}
}
# define swagger setting
SWAGGER_SETTINGS = {
"exclude_namespaces": [],
"api_version": '0.1',
"api_path": "",
"enabled_methods": [
'get',
'post',
'put',
'patch',
'delete'
],
"api_key": '',
"is_authenticated": True,
"is_superuser": False,
'SECURITY_DEFINITIONS': {
"api_key": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
},
},
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
# 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',
},
]
# database query logs settings
# Allows us to check db hits
# useful to optimize db query and hit
LOGGING1 = {
"version": 1,
"filters": {
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue"
}
},
"handlers": {
"console": {
"level": "DEBUG",
"filters": [
"require_debug_true"
],
"class": "logging.StreamHandler"
}
},
# database logger
"loggers": {
"django.db.backends": {
"level": "DEBUG",
"handlers": [
"console"
]
}
}
}
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
# language code
LANGUAGE_CODE = 'en-us'
# time zone
TIME_ZONE = 'UTC'
# define I18N
USE_I18N = True
# define L10N
USE_L10N = True
# define TZ
USE_TZ = True
# cors header settings
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# cors allow method
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
)
# cors allow header
CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'account-agent',
'x-csrftoken',
'x-requested-with',
)
# CORS header settings
CORS_EXPOSE_HEADERS = (
'Access-Control-Allow-Origin: *',
)
# Firebase settings
FIREBASE_APP = initialize_app()
# fcm django settings
FCM_DJANGO_SETTINGS = {
"APP_VERBOSE_NAME": "ZOD_Bank",
"ONE_DEVICE_PER_USER": False,
"DELETE_INACTIVE_DEVICES": True,
"UPDATE_ON_DUPLICATE_REG_ID": True,
}
"""Static files (CSS, JavaScript, Images)
https://docs.djangoproject.com/en/3.0/howto/static-files/"""
# google client id
GOOGLE_CLIENT_ID = os.getenv('GOOGLE_CLIENT_ID')
# google client secret key
GOOGLE_CLIENT_SECRET = os.getenv('GOOGLE_CLIENT_SECRET')
# CELERY SETUP
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
# email settings
EMAIL_BACKEND = os.getenv("MAIL_BACKEND")
EMAIL_HOST = os.getenv("MAIL_HOST")
EMAIL_PORT = os.getenv("MAIL_PORT")
EMAIL_USE_TLS = os.getenv("MAIL_USE_TLS")
EMAIL_HOST_USER = os.getenv("MAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("MAIL_HOST_PASSWORD")
EMAIL_FROM_ADDRESS = os.getenv("MAIL_FROM_ADDRESS")
DEFAULT_ADDRESS = os.getenv("DEFAULT_ADDRESS")
# ali baba cloud settings
ALIYUN_OSS_ACCESS_KEY_ID = os.getenv('ALIYUN_OSS_ACCESS_KEY_ID')
ALIYUN_OSS_ACCESS_KEY_SECRET = os.getenv('ALIYUN_OSS_ACCESS_KEY_SECRET')
ALIYUN_OSS_BUCKET_NAME = os.getenv('ALIYUN_OSS_BUCKET_NAME')
ALIYUN_OSS_ENDPOINT = os.getenv('ALIYUN_OSS_ENDPOINT')
ALIYUN_OSS_REGION = os.getenv('ALIYUN_OSS_REGION')
# define static url
STATIC_URL = 'static/'
# define static root
STATIC_ROOT = 'static'
# media url
MEDIA_URL = "/media/"
# media path
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')