import logging
import os
# Django settings for p4l project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

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

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["*"]

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

#absolute path of the src folder 
BASE_DIR = os.path.dirname(os.path.abspath(__file__)).rstrip("/")+"/"

#absolute url of the website without the host nor the protocol
BASE_URL = '/~ymh/p4l/'

#Host and protocol of the website
WEB_URL = 'http://localhost'

#absolute url of the website static resources
BASE_STATIC_URL = WEB_URL + BASE_URL + 'static/'
# absolute path for the website static resources  
BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../../web/static/").rstrip("/")+"/"

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = BASE_STATIC_ROOT + "media/"

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = BASE_STATIC_URL + "media/"

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = BASE_STATIC_ROOT + "site/"

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = BASE_STATIC_URL + 'site/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'change_this_with_very_secret_key'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'p4l.wsgi.application'

#absolute patrh to the logging file
LOG_FILE = os.path.abspath(os.path.join(BASE_DIR,"../../run/log/log.txt"))
#logging level
LOG_LEVEL = logging.DEBUG


#logging configuration
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': {
        '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': 'DEBUG',
            'propagate': True,
        },
        'django.request': {
            'handlers': ['file'],
            'level': 'ERROR',
            'propagate': True,
        },
        'p4l': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'core': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'rdflib_sqlalchemy': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'rdflib.term': {
            'handlers': ['file'],
            'level': 'DEBUG',
            'propagate': True,
        },    
    }
}

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

# Control the activation of the real time indexing.
REALTIME_INDEXING = True

# pagination of the list of record
NB_RECORDS_BY_PAGE = 20

# url of the sesame repository containing all the rdf referentials
SPARQL_QUERY_ENDPOINT = "http://localhost:8080/openrdf-sesame/repositories/plan4learning"

# cf http://docs.python.org/2/library/subprocess.html#popen-constructor
ADMIN_SCRIPT = {
    'args' : [ sys.executable, "manage.py", "dump_record", "--newline", "-j", "/tmp/script_dump.rdf.bz2"],
    'cwd' : "/Users/ymh/dev/workspace/plan4learning/src",
    'env' : {'PYTHONPATH': '/Users/ymh/dev/venvs/p4l/lib/python2.7/site-packages'}
}

