"""
Django settings for dsaas project.

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

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

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

import os
DATA_UPLOAD_MAX_MEMORY_SIZE = 31457280
SECRET_KEY = '53&hk10)my28gys=85y-ihqn7cz*^^4%gl@93o+0$x%mj6g(w6'

PROJECT_ROOT = os.path.abspath(
    os.path.join(os.path.dirname(__file__), ".."),
)

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



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

PREPEND_WWW = True
BASE_URL = "https://www.brayn.ai"
ALLOWED_HOSTS = ['127.0.0.1','localhost']
# for sending mails
# EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend"
# EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend"
# EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend"

#mailgun
# ANYMAIL = {

#     "MAILGUN_API_KEY": "<your API key>",
# }
#send in blue
ANYMAIL = {

    "SENDINBLUE_API_KEY": "key",
}
#AWS SES
# ANYMAIL = {

#     "AMAZON_SES_CLIENT_PARAMS": {
#         # example: override normal Boto credentials specifically for Anymail
#         "aws_access_key_id": "AWS_KEY",
#         "aws_secret_access_key": "ACCESSKye,
#         "region_name": "us-east-2",
#         # override other default options
#         "config": {
#             "connect_timeout": 30,
#             "read_timeout": 30,
#         }
#     },
# }

#sendgrid
# ANYMAIL = {

#    "SENDGRID_API_KEY": "Key",
# }

# Application definition

INSTALLED_APPS = [
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admindocs',
    'coreapp',
    "anymail",
    'seo_app',
    'webapp',
    'cronjob',
    'mlapp',
    #for django plotly
     'django_plotly_dash.apps.DjangoPlotlyDashConfig',
     #login app
     'login',
     'dal',
     'dal_select2',
     #dataintegration app
     'dataintegration',
     'adminapp',
     'actstream',
     'captcha',
     'rest_framework',
     'rest_framework.authtoken',
     "rest_framework_api_key",
    # 'debug_toolbar',

     'api',
     # written these two down because, login app takes following two apps for password reset. If written above login, django runs default auths.
     'django.contrib.admin',
     'django.contrib.auth',
     'django_extensions',
     'silk',
     'qdesk',
]



ACTSTREAM_SETTINGS = {
    'MANAGER': 'coreapp.managers.MyActionManager',
    'FETCH_RELATIONS': True,
    'USE_PREFETCH': True,
    'USE_JSONFIELD': False,
    'GFK_FETCH_DEPTH': 1,
}
ACTSTREAM_SETTINGS = {
    'MANAGER': 'login.managers.MyActionManager',
    'FETCH_RELATIONS': True,
    'USE_PREFETCH': True,
    'USE_JSONFIELD': False,
    'GFK_FETCH_DEPTH': 1,
}
MIDDLEWARE = [
    'silk.middleware.SilkyMiddleware',
    'dsaas.middleware.GCMiddleware',
    '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',
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
]

ROOT_URLCONF = 'dsaas.urls'

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (

    ),
    'DEFAULT_AUTHENTICATION_CLASSES': [

    ],
     "DEFAULT_PERMISSION_CLASSES": [

    ]

}
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, '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 = 'dsaas.wsgi.application'

INTERNAL_IPS = [
    # ...
    '127.0.0.1',
    # ...
]
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

# Production sqlite3
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#     }
# }
#
#Local sqlite3
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'localdb.sqlite3'),
    }
}


#cloudmysql credentials
# DATABASES = {
#        'default': {
#            'ENGINE': 'django.db.backends.mysql',
#            'NAME': 'DbName',
#            'USER': 'user',
#            'PASSWORD': 'Password',
#            'HOST': 'Host',
#       }
# }



# Password validation
# https://docs.djangoproject.com/en/2.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/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOGIN_REDIRECT_URL = '/customer/login-permission/'

LOGOUT_REDIRECT_URL = '/'


# SSL Code

SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')


# #
# STATIC_ROOT = 'static/'
# STATIC_URL = '/static/'
# #
# MEDIA_ROOT = 'media'
# MEDIA_URL = 'media/'


# #Un comment the below code before deployment
#
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_PROJECT_ID = 'Project Name'

GS_BUCKET_NAME = 'Bucket '
from google.oauth2 import service_account

GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
    "credentials.json"
)

DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_PROJECT_ID = 'Projetid'

GS_BUCKET_NAME = 'bucket Name'
from google.oauth2 import service_account

GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
    "credentials.json"
)
STATIC_ROOT = 'static'
STATIC_URL = 'static/'
# MEDIA_ROOT = 'https://storage.googleapis.com/brayn-media/'
MEDIA_URL  = 'media/'

#end un comment the below code before deployment

#### logging

# LOGGING = {
#     'version': 1,
#     'disable_existing_loggers': False,
#     'formatters': {
#             'verbose': {
#                 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
#                 'style': '{',
#             },
#             'simple': {
#                 'format': '{levelname} {message}',
#                 'style': '{',
#             },
#         },
#
#     'handlers': {
#         'console': {
#             'class': 'logging.StreamHandler',
#             'formatter': 'simple',
#         },
#         'file': {
#                     'class': 'logging.FileHandler',
#                     'filename': os.path.join('logbucket', 'complete_log.txt'),
#                     'mode':'w',
#                     'formatter': 'verbose',
#                 },
#     },
#     'root': {
#         'handlers': ['console', 'file'],
#         'level': 'CRITICAL', # Use DEBUG or INFO to get extra messages in the logbucket/ folder. Else you can keep CRITICAL or ERROR
#     },
# }

#### Debugger
#INSTALLED_APPS.append(['debug_toolbar', 'pympler'])
# DEBUG_TOOLBAR_PANELS = (
#     'debug_toolbar.panels.timer.TimerDebugPanel',
#     'pympler.panels.MemoryPanel',
# )
