Files
zod-backend/zod_bank/settings.py

248 lines
6.9 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
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')
# 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 frame work apps here
'django_extensions',
'storages',
'drf_yasg',
'corsheaders',
'django.contrib.postgres',
'rest_framework',
# Add your custom apps here.
'django_ses',
'account',
'junior',
'guardian',
'web_admin',
# 'social_django'
]
# define middle ware here
MIDDLEWARE = [
# Add your middleware classes here.
'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),
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(hours=71, minutes=59, seconds=59, microseconds=999999),
}
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'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',
},
]
# 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 setting
CORS_ORIGIN_ALLOW_ALL = True
# 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',
)
"""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')
# email settings
EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST="smtp.sendgrid.net"
EMAIL_PORT="587"
EMAIL_USE_TLS="True"
EMAIL_HOST_USER="apikey"
EMAIL_HOST_PASSWORD="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"
EMAIL_FROM_ADDRESS="support@zodbank.com"
DEFAULT_ADDRESS="zodbank@yopmail.com"
# 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')
MAX_ARTICLE_CARD = os.getenv('MAX_ARTICLE_CARD', 6)
MIN_ARTICLE_SURVEY = os.getenv('MIN_ARTICLE_SURVEY', 5)
MAX_ARTICLE_SURVEY = os.getenv('MAX_ARTICLE_SURVEY', 10)
# define static url
STATIC_URL = 'static/'
# define static root
STATIC_ROOT = 'static'
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')