<reponame>BitMask-Technologies/route-lift-api<gh_stars>0
"""
Django settings for routelift_api_config project.

Generated by 'django-admin startproject' using Django 3.2.4.

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 json
import os
from pathlib import Path

from corsheaders.defaults import default_headers
from dotenv import load_dotenv
from firebase_admin import initialize_app

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
ENV_PATH = BASE_DIR / '.env'
load_dotenv(ENV_PATH)

# 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('SECRET_KEY')
ROOT_SECRET = os.getenv('ROOT_SECRET')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
APPEND_SLASH = False

ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',')

# Add 'prefix' to all urlpatterns
API_VERSION = os.getenv('API_VERSION')

# reset token expiration time
DURATION = os.getenv('DURATION')

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'django_celery_beat',
    'swagger_render',
    'channels',
    'api_utils',
    'data_transformer',
    'data_uploader',
    'errors',
    'audit_trail',
    'Logistics',
    'Users',
    'roles_and_permissions',
    'stops',
    'links',
    'fcm_django',
    'push_notifications',
    'queueapp',
    'message_templates',
]

MIDDLEWARE = [
    'api_utils.views.MultipleProxyMiddleware',
    # 'api_utils.views.TimezoneMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    # 'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'routelift_api_config.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 = 'routelift_api_config.wsgi.application'
ASGI_APPLICATION = 'routelift_api_config.asgi.application'

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.getenv('DB_NAME'),
        'USER': os.getenv('DB_USER'),
        'PASSWORD': os.getenv('DB_PASSWORD'),
        'HOST': os.getenv('DB_HOST'),
        'PORT': os.getenv('DB_PORT'),
    }
}

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_EXPOSE_HEADERS = [
    'Access-Control-Allow-Methods',
    'Access-Control-Allow-Origin',
    'Access-Control-Allow-Headers',
    'Access-Control-Max-Age'
]

CORS_ALLOW_HEADERS = list(default_headers) + [
    'Token',
    'Secret',
]

# 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 = 'UTC'

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 = '/static/'
STATIC_ROOT = BASE_DIR / 'static'
SWAGGER_YAML_FILENAME = '/docs/routelift-api-doc.yml'
PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.Argon2PasswordHasher',
]

# CHANNEL_LAYERS = {
#     "default": {
#         "BACKEND": "channels_redis.core.RedisChannelLayer",
#         "CONFIG": {
#             "hosts": [os.getenv('REDIS_HOST')]
#         },
#     },
# }

# # Celery config
# CELERY_BROKER_URL = os.getenv('BROKER_URL')
# CELERY_RESULT_BACKEND = os.getenv('RESULT_BACKEND')
# CELERY_ACCEPT_CONTENT = os.getenv('ACCEPT_CONTENT').split()
# CELERY_TASK_SERIALIZER = os.getenv('TASK_SERIALIZER')
# CELERY_RESULT_SERIALIZER = os.getenv('RESULT_SERIALIZER')
# CELERY_IMPORTS = os.getenv('IMPORTS').split()
# CELERY_TIMEZONE = os.getenv('TIMEZONE')

# # Redis
# REDIS_SERVER_NAME = os.getenv('REDIS_SERVER')
# REDIS_PORT = os.getenv('REDIS_PORT')

# # Email setup
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_HOST = os.getenv('SMTP_HOST')
# EMAIL_HOST_USER = os.getenv('SMTP_HOST_USER')
# EMAIL_HOST_SENDER = os.getenv('SMTP_HOST_SENDER')
# EMAIL_HOST_PASSWORD = os.getenv('SMTP_HOST_PASSWORD')
# EMAIL_PORT = os.getenv('SMTP_PORT')
# EMAIL_USE_TLS = os.getenv('SMTP_USE_TLS')

# wasabi s3 bucket configuration
# BUCKET_ACCESS_KEY_ID = os.getenv('BUCKET_ACCESS_KEY_ID')
# BUCKET_SECRET_KEY = os.getenv('BUCKET_SECRET_KEY')
# BUCKET_REGION_NAME = os.getenv('BUCKET_REGION_NAME')
# BUCKET_NAME = os.getenv('BUCKET_NAME')
# BUCKET_ENDPOINT_URL = os.getenv('BUCKET_ENDPOINT_URL')
# DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
AWS_S3_FILE_OVERWRITE = False
BUCKET_REGION_NAME = os.getenv('BUCKET_REGION_NAME')
AWS_DEFAULT_ACL = None
BUCKET_ENDPOINT_URL = os.getenv('BUCKET_ENDPOINT_URL')

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

TEST_SECRET = os.getenv("ROOT_SECRET")

BROKER_URL = os.getenv('BROKER_URL')
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND')
CELERY_TASK_ALWAYS_EAGER = False
CELERY_ALWAYS_EAGER = False
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Africa/Lagos'
CELERY_TASK_TRACK_STARTED = True

CELERY_TASK_TENANT_CACHE_SECONDS = os.environ.get("TASK_TENANT_CACHE_SECONDS", 10)
CELERY_IMPORTS = [
    'data_uploader.tasks',
    'queueapp.views',
]

FIREBASE_APP = initialize_app()

FCM_DJANGO_SETTINGS = {
    "APP_VERBOSE_NAME": "FCM Django",
    "ONE_DEVICE_PER_USER": True,
    "DELETE_INACTIVE_DEVICES": True
}

# GAC_PATH = r"C:\Users\BEN-UNKNOWN\PycharmProjects\routeAPI\routelift_api\my-project-1509659734869-303d29ca73ca.json"
GAC_PATH = "my-project-1509659734869-303d29ca73ca.json"
with open(GAC_PATH) as gac_file:
    GOOGLE_APPLICATION_CREDENTIALS = json.load(gac_file)

BULK_SMS_SENDER = "Routelift"
BULK_SMS_BASE_URL = "https://api.sendchamp.com/api/v1/sms/"

BULK_SMS_HEADER = {
    'Accept': 'application/json',
    'Authorization': 'Bearer {}'.format(os.environ.get("BULK_SMS_ACCESS_KEY")),
    'Content-Type': 'application/json'
}
