# -*- coding: utf-8 -*-
from remieplt.settings import *
import os, logging

#TODO override
DEBUG = True
TEMPLATE_DEBUG = DEBUG


BASE_URL = '%(base_url)s'
WEB_URL = '%(web_url)s'

PLATFORM_BASE_URL = WEB_URL + BASE_URL + 'remieplt/'

STREAM_SRC_PREFIX = ""

BASE_STATIC_URL = WEB_URL + BASE_URL + 'static/'
BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../../web/static/").rstrip("/")+"/"

STREAM_URL = BASE_STATIC_URL + "/content/"

CAS_URLPARAMETER_NAME = "casticket"

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = BASE_STATIC_ROOT + "media/"

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = BASE_STATIC_URL + 'media/'


STATIC_URL = BASE_STATIC_URL + 'site/'

# Absolute path to the directory that static files (js, css, swf...)
# DO NOT forget to do command line ./manage.py collectstatic to gather static media into the web/static folder
STATIC_ROOT = BASE_STATIC_ROOT + "site/"

CONTENT_ROOT = MEDIA_ROOT + "/content/"

STREAM_PATH = CONTENT_ROOT


SRC_BASE_URL = BASE_URL + __name__.split('.')[0] + '/'

LOGIN_URL = SRC_BASE_URL + 'accounts/login/'
LOGOUT_URL = SRC_BASE_URL + 'accounts/disconnect/'
LOGIN_REDIRECT_URL = SRC_BASE_URL + 'ldt/'
LOGOUT_REDIRECT_URL = SRC_BASE_URL + 'accounts/login'
PROFILE_REDIRECT_URL = SRC_BASE_URL + 'auth_accounts/create/profile'
LOGIN_ERROR_URL = SRC_BASE_URL + 'accounts/login'


CORS_URLS_REGEX = r"^" + BASE_URL + 'remie/api/.*$'


# Make this unique, and don't share it with anybody.
SECRET_KEY = '%(secret_key)s'

# PATH to the ffmpeg executable, used to know automatically the media file duration
FFMPEG_PATH = ""


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.%(db_engine)s', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '%(db_name)s',                      # Or path to database file if using sqlite3.
        'USER': '%(db_user)s',                      # Not used with sqlite3.
        'PASSWORD': '%(db_password)s',                  # Not used with sqlite3.
        'HOST': '%(db_host)s',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '%(db_port)d',                      # Set to empty string for default. Not used with sqlite3.
    },
}

LOG_FILE = os.path.abspath(os.path.join(BASE_DIR,"../run/log/log.txt"))
LOG_LEVEL = logging.DEBUG

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'formatters' : {
        'simple' : {
            'format': "%(asctime)s - %(levelname)s : %(message)s",
        },
        'semi-verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(message)s'
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'stream_to_console': {
            'level': LOG_LEVEL,
            'class': 'logging.StreamHandler'
        },
        'file': {
            'level': LOG_LEVEL,
            'class': 'logging.FileHandler',
            'filename': LOG_FILE,
            'formatter': 'semi-verbose',
        },
    },
    'loggers': {
#        'django.db.backends':{
#            'handlers': ['file'],
#            'level': LOG_LEVEL,
#            'propagate': True,
#        },
        'django.request': {
            'handlers': ['file'],
            'level': LOG_LEVEL,
            'propagate': True,
        },
        'ldt': {
            'handlers': ['file'],
            'level': LOG_LEVEL,
            'propagate': True,
        },
#        'pyelasticsearch': {
#            'handlers': ['file'],
#            'level': LOG_LEVEL,
#            'propagate': True,
#        },
    }
}


ADMINS = (
    #('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

GOOGLE_ANALYTICS_CODE = None


ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = False

LDT_MAX_SEARCH_NUMBER = 50
LDT_JSON_DEFAULT_INDENT = 2

EMPTY_MEDIA_EXTERNALID = None

FRONT_TAG_LIST = [u"Enmi 2011", u"film", u"conférence"]

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'ldt.indexation.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'ldt',
    },
}
