"""
Django settings for ESite project.

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

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

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

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

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%n%1xu43ytm*5z9o347qwb#^osx23y%a+$wgtv9n!r@u@qmyn$'

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

ALLOWED_HOSTS = []

SITE_ID = 1
# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'haystack',
    'econ',
    'dal',
    'dal_select2',
    'django_mptt_admin',
    'social_django',
    'mptt',
    # 'import_export',
    # 'django_comments',
    "compressor",
    'ckeditor',
    'cacheops',
    'hitcount',
    'tagging',
    # 'zinnia',
    # 'ckeditor_uploader',
    'nested_admin',
    'graphene_django',
)


MIDDLEWARE = (
    # 'django.middleware.cache.UpdateCacheMiddleware',
    '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.security.SecurityMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',
    # 'django.middleware.cache.FetchFromCacheMiddleware',
    # 'debug_toolbar.middleware.DebugToolbarMiddleware',
)

ROOT_URLCONF = 'ESite.urls'

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',
                'social_django.context_processors.backends',  # <--
                'social_django.context_processors.login_redirect',
                # 'zinnia.context_processors.version', 
                'econ.context_processor.cagetory_list',
            ],
            # 'loaders':[
            #     'django.template.loaders.filesystem.Loader',
            #     'django.template.loaders.app_directories.Loader',
            # ]
        },
    },
]

AUTHENTICATION_BACKENDS = (
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.google.GoogleOpenId',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.google.GoogleOAuth',
    'django.contrib.auth.backends.ModelBackend',
)

WSGI_APPLICATION = 'ESite.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'esite',
        'USER': 'root',
        'PASSWORD': 'qwe',
        'OPTIONS': {
            'charset': 'utf8mb4',
            # 'init_command': ("SET GLOBAL time_zone='%s'" % '+7:00'),
        },
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

# USE_TZ = True

# LOGIN_URL = 'login'
LOGOUT_URL = 'index'


SOCIAL_AUTH_FACEBOOK_KEY = '1472925602767492'  # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = 'd68f6faf5dca9addeb4b0a8d0db0e4e1'  # App Secret
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', 'public_profile', ]
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': 'id, name, email, cover, gender', 
    'locale': 'en_US',
}

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '787750051756-iviqd3qlke519oooi925130fj1kmnq0g.apps.googleusercontent.com'  # App ID
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'STEIr2IaCVngvg_1Q0sLOGHT'  # App Secret


SOCIAL_AUTH_TWITTER_KEY = 'uD41ct94nBHuPuYgOYA83kIL9'
SOCIAL_AUTH_TWITTER_SECRET = '5aUztBHKmOZbNx4S9DQpeFvLz0jfVskvqIelIUUahCtLTvWhnX'

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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "staticfile")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"), )

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

MEDIA_URL = '/media/'

COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'django_libsass.SassCompiler'),
)


CACHEOPS_REDIS = {
    'host': 'localhost', # redis-server is on same machine
    'port': 6379,        # default redis port
    'db': 1,             # SELECT non-default redis database
                         # using separate redis db or redis instance
                         # is highly recommended
    'socket_timeout': 3,   # connection timeout in seconds, optional
}


CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient"
        },
        "KEY_PREFIX": "example"
    }
}

GRAPHENE = {
    'SCHEMA': 'econ.schema.schema' # Where your Graphene schema lives
}


HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'haystack',
        'INCLUDE_SPELLING': True,
    },
}


CKEDITOR_UPLOAD_PATH = "media/"
from .ckeditor_conf import CKEDITOR_CONFIGS

# ZINNIA_MAIL_COMMENT_REPLY = False
# ZINNIA_MAIL_COMMENT_AUTHORS = False