"""
Django settings for moretvtime project.

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

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

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

import os
import socket

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

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GEOIP_PATH = os.path.abspath(os.path.join(BASE_DIR, 'django_server/geoip'))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3@0*@^3a8v-=n(h-p)a_-akicec_22947@#ijx=9k3)*ylzgst'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = socket.gethostname() != 'ubuntu-s-1vcpu-1gb-fra1-01'
#DEBUG=True


ALLOWED_HOSTS = [
    '127.0.0.1',
    '192.168.58.1',
    '192.168.1.73',
    '138.68.98.193',
    'moretvtime.com',
    'dev.moretvtime.com',
    'youlovepranks.com',
    'pranksforu.com',
    'funnypranks.me',
    'virallift.com',
    'dev.virallift.com'
]

SITE_ID = 1

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'rest_framework',
    'corsheaders',
    'djrichtextfield',
    'django_countries',
    'tracking',
    'moretvtime',
    'offerwall',
    'dashboard',
    'charts',
    # 'mathfilters'
    'ddtrace.contrib.django',
]

DATADOG_TRACE = {
    'DEFAULT_SERVICE': 'moretvtime',
    'TAGS': {'env': 'production'},
}

DATADOG_TRACE['ENABLED'] = True

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    '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',
    # 'moretvtime.middleware.CheckVpnAddressMiddleware',
    'moretvtime.middleware.Clearcookie_npMiddleware',

]

ROOT_URLCONF = 'django_server.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',
                'moretvtime.request_processor.categories',
            ],
            'loaders': [
                (
                    'django.template.loaders.filesystem.Loader',
                    [os.path.join(BASE_DIR, 'templates')],
                ),
                # 'django_server.template_loader.DynamicLoader',
                'django.template.loaders.app_directories.Loader',
                'admin_tools.template_loaders.Loader',
            ]
        }

    },
]

WSGI_APPLICATION = 'django_server.wsgi.application'


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


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'moretvtime',
        'USER': 'moretvtime',
        'PASSWORD': 'moretvtimemoretvtime',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
    },
    'handlers': {
        'default': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/moretvtime/app.log',
            'maxBytes': 1024*1024*500,
            'backupCount': 2,
            'formatter':'standard',
        },
        'request_handler': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/moretvtime/django_request.log',
            'maxBytes': 1024*1024*500,
            'backupCount': 2,
            'formatter':'standard',
        },
        'command_handler': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/moretvtime/command.log',
            'maxBytes': 1024*1024*500,
            'backupCount': 2,
            'formatter':'standard',
        },
        'db_handler': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/moretvtime/postgres.log',
            'maxBytes': 1024*1024*500,
            'backupCount': 2,
            'formatter':'standard',
        }
    },
    'loggers': {
        '': {
            'handlers': ['default'],
            'level': 'DEBUG',
            'propagate': True
        },
        'django.request': {
            'handlers': ['request_handler'],
            'level': 'DEBUG',
            'propagate': False
        },
        'moretvtime.management.commands': {
            'handlers': ['command_handler'],
            'level': 'DEBUG',
            'propagate': False
        },
        'ddtrace': {
            'handlers': ['default'],
            'level': 'WARNING',
        },
    }
}

DJRICHTEXTFIELD_CONFIG = {
    'js': ['//tinymce.cachefly.net/4.1/tinymce.min.js'],
    'init_template': 'djrichtextfield/init/tinymce.js',
    'settings': {
        'menubar': False,
        'plugins': 'link image',
        'toolbar': 'bold italic | link image | removeformat',
        'width': 700
    }
}



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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Calcutta'

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(BASE_DIR, 'article_images')
MEDIA_URL = '/article_images/'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
    path.join(BASE_DIR, 'static'),
    path.join(BASE_DIR, 'admin'),
]

STATIC_ROOT = path.join(BASE_DIR, '')
STATIC_URL = '/static/'

#####################   LOGIC   ##############################

CONNECTOR_HOST = '127.0.0.1:8000'
# CONNECTOR_HOST = 'moretvtime.com'

MC_SERVER = 'https://minglecash.com'
# MC_SERVER = 'http://127.0.0.1:8004'


CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_WHITELIST = (
    'gamesgalore.site',
    'dev.gamesgalore.site',
    'minglecash.com',
    'dev.minglecash.com',
    'localhost:8000',
    '127.0.0.1:8000',
    '127.0.0.1:3000',
    '127.0.0.1:80',
    '127.0.0.1',
    'localhost:80',
    '127.0.0.1:8000'
)
CORS_ALLOW_HEADERS = (
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'cache',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
)
CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
)

BTC_TOKEN = ''

USER_SIGNATURE_SALT = '2ASYN5pjVBCKLBP51r5S9XshjC1851jScgHg9CA8bij'

TRACKING_USE_GEOIP = True
TRACKING_TIMEOUT = 1  # in minutes

TRACKING_CLEANUP_TIMEOUT = 24  # in hours
NO_TRACKING_PREFIXES = [
    '/article_images/',
    '/admin/',
    '/contact',
    '/privacy',
    '/term',
    '/about'
]



