### BASE CONFIGURATION

import os.path
import posixpath
import logging
from txcommon.i18n import available_languages

# TX_ROOT variable is defined/overridden in settings.py.

# Transifex can also be run from another "project" dir. To do so,
# define the PROJECT_PATH in the project's dir and point TX_ROOT
# to the directory holding the transifex source code.

try:
    PROJECT_PATH
except NameError:
    PROJECT_PATH = TX_ROOT


# Path for the log file
LOG_PATH = os.path.join(PROJECT_PATH, 'logs')
# Logging level/verbosity.
# Choices: DEBUG (default), INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL = 'DEBUG'

if not os.path.exists(LOG_PATH):
    os.mkdir(LOG_PATH, 0755)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'tx_file': {
            'format': '%(asctime)s %(levelname)s %(message)s',
        },
        'tx_stream': {
            'format': '[%(asctime)s %(name)s %(levelname)s] %(message)s',
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'log_to_file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': os.path.join(LOG_PATH, 'transifex.log'),
            'mode': 'a+',
            'formatter': 'tx_file',
        },
        'log_to_stream': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'tx_stream',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'tx': {
            'handlers': ['log_to_file', 'log_to_stream', ],
            'level': LOG_LEVEL,
            'propagate': False,
        }
    },
}

# Uncomment, to log the executed SQL queries
# LOGGING['loggers']['django.db.backends'] = {
#     'handlers': ['log_to_file'],
#     'level': LOG_LEVEL,
#     'propagate': False,
# }



# 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.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'UTC'

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

LOCALE_PATHS = (os.path.join(PROJECT_PATH, 'locale/'),)

# define dummy gettext function, see https://docs.djangoproject.com/en/dev/ref/settings/#languages
gettext = lambda s: s
# Take the languages automatically from the correct places
LANGUAGES = available_languages(LOCALE_PATHS[0])
LANGUAGES.append((LANGUAGE_CODE, gettext(LANGUAGE_NAME)))
LANGUAGES.sort()

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# The absolute path to the directory that holds static files
STATIC_ROOT = os.path.join(PROJECT_PATH, 'site_media/static/')

# URL that handles the files served from STATIC_ROOT
STATIC_URL = '/site_media/static/'

STATICFILES_DIRS = [
    ('', os.path.join(PROJECT_PATH, 'static')),
]

# Absolute path to the directory that holds media.
# This is targeted for dynamically-produced static media, such as file
# uploads, avatars, etc.
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'site_media/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/"
# NOTE: Also, this is hard-coded in the base.html template, so that the 500
# error page works. You'll need to change the occurrences in that file too.
MEDIA_URL = '/site_media/media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = posixpath.join(STATIC_URL, "admin/")

# Make this unique, and don't share it with anybody.
SECRET_KEY = r"[[SECRETKEY]]"

