# -*- coding: utf-8 -*-
import os, logging

SITE_ID = 1

#configuration for runserver
#BASE_URL = '/'
#PLATFORM_BASE_URL = '/'
#WEB_URL = ''
#WEB_AUTH = []



#BASE_DIR = os.path.dirname(os.path.abspath(__file__)).rstrip("/")+"/"
BASE_DIR = '%(base_dir)s'
BASE_URL = '%(base_url)s'
PLATFORM_BASE_URL = BASE_URL + 'spel/'
WEB_URL = '%(web_url)s'
WEB_AUTH = [] # example [{'REGEX': 'localhost/~ymh/spel', 'NAME': 'ymh', 'PASSWORD': 'ymh'}]
STATIC_URL = BASE_URL + 'static/site/'


STREAM_URL = "%(stream_url)s"

STREAM_SRC_PREFIX = "%(stream_src_prefix)s"
 
BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../static/").rstrip("/")+"/"
BASE_STATIC_URL = BASE_URL + 'static/' 

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


# 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/"

# 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 = "%(ffmpeg_path)s"


CONTENT_ROOT = BASE_STATIC_ROOT + "content/"

# PATH where uploaded media are put.
STREAM_PATH = CONTENT_ROOT

LDT_MEDIA_PREFIX = STATIC_URL + 'ldt/'



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.
    }
}

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    }
}

DEBUG = True
TEMPLATE_DEBUG = DEBUG

#LOG_FILE = os.path.abspath(os.path.join(BASE_DIR,"../../run/log/log.txt"))
LOG_FILE = '%(log_file)s'
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,
        },
        'spel': {
            'handlers': ['file'],
            'level': LOG_LEVEL,
            'propagate': True,
        },
    }
}


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

MANAGERS = ADMINS

GOOGLE_ANALYTICS_CODE = '%(google_analytics_code)s'

EMAIL_USE_TLS = %(email_use_tls)s
EMAIL_HOST = '%(email_host)s'
EMAIL_HOST_USER = '%(email_host_user)s'
EMAIL_HOST_PASSWORD = '%(email_host_user)s'
EMAIL_PORT = %(email_port)d 

ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_OPEN = False

LDT_MAX_SEARCH_NUMBER = 50
LDT_MAX_FRAGMENT_PER_SEARCH = 3
LDT_RESULTS_PER_PAGE = 1
LDT_JSON_DEFAULT_INDENT = 0
LDT_MAX_CONTENTS_PER_PAGE = 5
LDT_MAX_PROJECTS_PER_PAGE = 5
LDT_FRONT_MEDIA_PER_PAGE = 9

EMPTY_MEDIA_EXTERNALID = None

AUTO_INDEX_AFTER_SAVE = True

FORBIDDEN_STREAM_URL = "%(forbidden_stream_url)s"

AUDIO_RECORD_URL = "%(audio_record_url)s"

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

HAYSTACK_CONNECTIONS = {
    'default': {
        #for elasticsearch use ldt.indexation.backends.elasticsearch_backend.ElasticsearchSearchEngine
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
        #'URL': 'http://127.0.0.1:9200/',
        #'INDEX_NAME': 'spel',
    },
}

LDT_INDEXATION_INSERT_BATCH_SIZE = 5000