chidioguejiofor/airtech-api

View on GitHub
airtech_api/settings/base.py

Summary

Maintainability
A
0 mins
Test Coverage
"""
Django settings for airtech_api project.

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

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import dj_database_url
from dotenv import load_dotenv
import cloudinary

load_dotenv()

CLOUD_API_KEY = os.getenv('CLOUDINARY_API_KEY')
CLOUDINARY_SECRET = os.getenv('CLOUDINARY_SECRET')
CLOUDINARY_NAME = os.getenv('CLOUDINARY_NAME')
cloudinary.config(cloud_name=CLOUDINARY_NAME,
                  api_key=CLOUD_API_KEY,
                  api_secret=CLOUDINARY_SECRET)

DEBUG = True
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# DJANGO_SETTINGS_MODULE= os.getenv('DJANGO_SETTINGS_MODULE', 'airtech_api.settings')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/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', True)

ALLOWED_HOSTS = ['airtech-api.herokuapp.com', 'localhost']

# Application definition

INSTALLED_APPS = [
    'corsheaders',
    'rest_framework',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'airtech_api.users',
    'airtech_api.utils',
    'airtech_api.flight',
    'airtech_api.booking',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    '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',
]

ROOT_URLCONF = 'airtech_api.urls'

print(BASE_DIR)
print(BASE_DIR + '/services/email_service/templates')
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR + '/services/email_service/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',
            ],
        },
    },
]

WSGI_APPLICATION = 'airtech_api.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
    'default': dj_database_url.parse(os.getenv('DATABASE_URI'),
                                     conn_max_age=600)
}

# Password validation
# https://docs.djangoproject.com/en/2.1/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',
    },
]
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = '*'
# Internationalization
# https://docs.djangoproject.com/en/2.1/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/2.1/howto/static-files/

STATIC_URL = '/static/'

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS':
    'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    # 'TEST_REQUEST_DEFAULT_FORMAT': 'json',
    'DEFAULT_MODEL_SERIALIZER_CLASS':
    'drf_toolbox.serializers.ModelSerializer',
}

ENVIRONMENT = os.getenv('ENVIRONMENT', 'development')

if ENVIRONMENT.lower() == 'docker_dev':
    from .docker_dev import *

if ENVIRONMENT.lower() != 'production':
    ALLOWED_HOSTS.append('*')
if ENVIRONMENT.lower() == 'production':
    DEBUG = False