"""
Django settings for web_admin 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
import sys

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'dvph%ti#3)^p^a)+pmi*mv)j%)_4rq)302()yx-_lpj4-!(9_x'

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

ALLOWED_HOSTS = ['*']

# Application definition
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
     'mod_wsgi.server',

    'authentications',
    'clients',
    'balances',
    'web',
    'agent_type',
    'system_user',
    'service_group',
    'services',
    'agents',
    'customers',
    'cards',
    'card_type',
    'cash_sofs',
    'bank_sofs',
    'bank',
    'payments',
    'api_management',
    'centralize_configuration',
    'reconcile',
    'card_design',
    'card_provider',
    'card_sofs',
    'balance_adjustment',
    'campaign',
    'fraud_prevention',
    'rule_configuration',
    'voucher',
    'report_configuration',
    'product',
    'category',
    'shop_type',
    'shop_category',
    'shop',
    'channel_gateway.service',
    'channel_gateway.api',
    'password_center',
    'upload_management',
    'authentications.one_time_password_report',
    'trust_management'
]

MIDDLEWARE_CLASSES = [
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
    # 'debug_panel.middleware.DebugPanelMiddleware',

    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    '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',
    'django.middleware.locale.LocaleMiddleware',
    'authentications.apps.InvalidAccessTokenException',
]

# Load configuration from configuration file
sys.path.append('/data/projects/admin-portal/config')
from platform_settings import *

AUTHENTICATION_BACKENDS = ('authentications.apps.CustomBackend',)
# Add this to tell Django where to redirect after
# successful login

ROOT_URLCONF = 'web_admin.urls'

PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))

STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'),
                 os.path.join(PROJECT_PATH, 'web', 'templates', 'voucher', 'clients', 'oauth_client', 'balances', 'agent_type',
                              'configuration', 'system_user', 'service_group', 'services', 'agents', 'customers',
                              'cards', 'card_type', 'cash_sofs', 'payments', 'bank', 'sof', 'card_design', 'card_provider',
                              'reconcile', 'permissions', 'card_sofs', 'balance_adjustment','campaign', 'fraud_prevention',
                              'rule_configuration', 'report_configuration','product', 'category', 'shop_type',
                              'password_center', 'upload_management', 'trust_management')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.static',
                'django.contrib.messages.context_processors.messages',
            ],
            'builtins': ['authentications.templatetags.common_tags']
        },
    },
]

OPTIONS = {
    'libraries': {
        'myapp_tags': 'authentications.templatetags',
    },
}

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/admin-portal/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

WSGI_APPLICATION = 'web_admin.wsgi.application'

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



# 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',
    },
]

LOGIN_REDIRECT_URL = 'web:web-index'
# 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

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': "%(asctime)s,%(msecs)03d | %(levelname)s | AMI | AppLog | ami-admin-portal | %(correlationId)s | %(thread)d  | %(IPAddress)s | %(name)s | %(message)s",
            'datefmt': "%Y-%m-%dT%H:%M:%S"
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
            'stream': "ext://sys.stdout"
        }
    },
    'loggers': {
        'authentications': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'clients': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'agent_type': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'balances': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'configuration': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'system_user': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'service_group': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'services': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'agents': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'customers': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'cards': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'card_type': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'api_management': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'centralize_configuration': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'cash_sofs': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'bank_sofs': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'bank': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'payments': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'reconcile': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'card_design': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'card_provider': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'card_sofs': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'balance_adjustment': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'campaign': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'fraud_prevention': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'rule_configuration': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'voucher': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'report_configuration': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'product': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'category': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'shop_type': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'shop_category': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'shop': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'channel_gateway': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'web_admin': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'password_center': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'upload_management': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'one_time_password_report': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },
        'trust_management': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        }
    }
}

FILE_UPLOAD_MAX_MEMORY_SIZE = 10485760

