"""
Django settings for phendo_api project.

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

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

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

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from django.core.urlresolvers import reverse

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/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
#SECRET_KEY = '0e11o&v!$e^to*m+n&#8iboel+mt93@2te$6l!%gfplxu7ip=y'
# srlg replaced the original trialX SECRET_KEY
SECRET_KEY = 'rg34)h)ec81du#ze0$dea=$uo5&^u-phcpk3ic(z38=32sb@*w'

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

# srlg must change this !!!
ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'rest_framework',
    'rest_framework.authtoken',
    'participant.apps.ParticipantConfig',
    'survey.apps.SurveyConfig',
    'security.apps.SecurityConfig'
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'security.middleware.ValidateStudyTokenMiddleware',
    'security.middleware.ValidateParticipantTokenMiddleware',
    'security.middleware.ProcessExceptionMiddleware',
    # 'audit_log.middleware.JWTAuthMiddleware',
    'audit_log.middleware.UserLoggingMiddleware',
]

ROOT_URLCONF = 'phendo_api.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 = 'phendo_api.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/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/1.9/howto/static-files/

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_AUTHENTICATION_CLASSES': [],
    'DEFAULT_PERMISSION_CLASSES': [],
    'UNICODE_JSON': True,
    'DATETIME_FORMAT': "%Y-%m-%dT%H:%M:%S%z",
}
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

#DJANGO_LOG_LEVEL=DEBUG
ROOT_LOG_PATH = '/var/www/html/phendo-backend/log/'
#ROOT_LOG_PATH = '/phendo-backend/log/'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False, 
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'formatters': {
        'standard': {
        'format': '%(asctime)s [%(levelname)s] %(name)s:%(funcName)s:%(lineno)d: %(message)s'
        },
   },
    'handlers': {

        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(ROOT_LOG_PATH, 'phendo.log'),
            'maxBytes' : 1024*1024*5,  # 5 mg
            'backupCount': 14,
            'formatter': 'standard',
        },
        'django.server': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(ROOT_LOG_PATH, 'phendo-server.log'),
            'maxBytes' : 1024*1024*5,  # 5 mg
            'backupCount': 14,
            'formatter': 'standard',
        },
        'django.db.backends': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename':  os.path.join(ROOT_LOG_PATH, 'phendo-db-backend.log'),
            'maxBytes' : 1024*1024*5,  # 5 mg
            'backupCount': 14,
            'formatter': 'standard',
        },
        'django.template' : {
            'level': 'ERROR',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename':  os.path.join(ROOT_LOG_PATH, 'phendo-template.log'),
            'maxBytes' : 1024*1024*5,  # 5 mg
            'backupCount': 14,
            'formatter': 'standard',
        },
        'request_handler' : {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(ROOT_LOG_PATH, 'django_request.log'),
            'maxBytes' : 1024*1024*5,  # 5 mg
            'backupCount': 14,
            'formatter': 'standard',
        },
        'console': {
            'level': 'INFO',
            'filters': ['require_debug_false'],
            'class': 'logging.StreamHandler',
            'formatter': 'standard',
        },
       
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
  
    'loggers': {
        '': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'phendo-log': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'django': {
            'handlers': ['file'], #'console'
            'level': 'DEBUG',
            'propagate': False,
        },
        'django.server': {
            'handlers': ['django.server'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'django.request': {
            'handlers': ['request_handler'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'django.security': {
            'handlers': ['mail_admins', 'file'],
            'level': 'ERROR',
            'propagate': False,
        },
        'django.db.backends' : {
            'handlers': ['console', 'django.db.backends'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'django.template' : {
            'handlers': ['console', 'django.template'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'py.warnings': {
            #'handlers': ['console'],
            'handlers': ['file'],
            'propagate': True,
        },
    }
}

SITE_DOMAIN = "https://citizenendo.dbmi.columbia.edu"

EMAIL_HOST = 'Nova.cpmc.columbia.edu'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = "citizenendo@columbia.edu"

GLOBAL_VALIDATION_SKIP = ['admin', 'getcode', 'total', 'auth_verify', 'auth_login']
STUDY_TOKEN_SKIP_VALIDATION = GLOBAL_VALIDATION_SKIP + [
    'study_token',
    'schema_url',
    'total',
]
PARTICIPANT_TOKEN_SKIP_VALIDATION = GLOBAL_VALIDATION_SKIP + [
    'study_token',
    'participant_token',
    'surveys',
    'survey_question',
    'questions',
    # 'allowed_responses',
    'survey_type',
    'schema_url',
    'total',
]
CONSENT_SECTIONS_AVAILBLE = (
    ('overview', 'Overview'),
    ('data_gathering', 'Data Gathering'),
    ('privacy', 'Privacy'),
    ('data_use', 'Data Use'),
    ('time_commitment', 'Time Commitment'),
    ('surveys', 'Surveys'),
    ('tasks', 'Tasks'),
    ('withdrawal', 'Withdrawal'),
    ('sharing_options', 'Sharing Options'),
    ('custom', 'Custom Document'),
)

SKIP_POST_CALLS_ONLY = GLOBAL_VALIDATION_SKIP + [
    'participant_study',
    'schema_url',
]

APNS_SANDBOX=False
APNS_CERT_FILE="{0}/cert/ProdPhendo.pem".format(BASE_DIR)

REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        # 'rest_framework.renderers.BrowsableAPIRenderer',
    )
}

ANDROID_API_KEY="AAAABsPG-2Q:APA91bEAxespTug2IHG2zTfiQ9DjbatRWFV6TjDlOzRfaPXh1TSiZj79TI4SMWOPflePOkYK4_Mx8uy1i0XS1vQmAf3Z4_vks8GG5CPfCR6fmJnLs1vbSJ9Z2JQmORzQzTjmLjwyRXVs"
FCM_URL = "https://fcm.googleapis.com/fcm/send"

from local_settings import *

