import os
from django.utils.translation import ugettext_lazy as _
import dj_database_url


SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')

gettext = lambda s: s
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATA_DIR = os.path.join(BASE_DIR)

"""
Django settings for CBF project.

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

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, ...)
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!


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

ALLOWED_HOSTS = []


# Application definition

ROOT_URLCONF = 'CBF.urls'

WSGI_APPLICATION = 'CBF.wsgi.application'

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

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

LANGUAGE_CODE = 'es'

TIME_ZONE = 'America/Santo_Domingo'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
STATIC_ROOT = os.path.join(DATA_DIR, 'static')

SITE_ID = 1


# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
    # 'django.contrib.staticfiles.finders.DefaultStorageFinder',

)



TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'CBF'),],
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.i18n',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.media',
                'django.template.context_processors.csrf',
                'django.template.context_processors.tz',
                'sekizai.context_processors.sekizai',
                'django.template.context_processors.static',
                'cms.context_processors.cms_settings'
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader'
            ],
        },
    },
]


MIDDLEWARE_CLASSES = (
    'cms.middleware.utils.ApphookReloadMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # subdomains
    'subdomains.middleware.SubdomainURLRoutingMiddleware',

    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
)

INSTALLED_APPS = (
    'djangocms_admin_style',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.staticfiles',
    'django.contrib.messages',
    'cms',
    'menus',
    'sekizai',
    'treebeard',
    'djangocms_text_ckeditor',
    'filer',
    'easy_thumbnails',
    'djangocms_column',
    'djangocms_link',
    'cmsplugin_filer_file',
    'cmsplugin_filer_folder',
    'cmsplugin_filer_image',
    'cmsplugin_filer_utils',
    'djangocms_style',
    'djangocms_snippet',
    'djangocms_googlemap',
    'djangocms_video',

    # local apps
    'CBF',
    'sermons',
    'thoughts',
    'cells',
    'membership',
    'events',
    'books',
    'widgets',
    'home',
    'about_us',
    'tcd',

    # third_party
    'subscribers',
    'anymail',
    'fontawesome',
    'compressor',
    'django_extensions',
    'analytical',
    'django_celery_results',
    'django_celery_beat',
    'newsletter',
    'subdomains',

)

LANGUAGES = [
    ## Customize this
    ('en', _('English')),
    ('es', _('Spanish')),

]


CMS_LANGUAGES = {
    # Customize this
    1: [
        {
            'redirect_on_fallback': True,
            'hide_untranslated': False,
            'name': gettext('en'),
            'code': 'en',
            'public': True,
        },
    ],
    'default': {
        'redirect_on_fallback': True,
        'hide_untranslated': False,
        'public': True,
    },
}

CMS_TEMPLATES = [
    # Customize this
    ('CBF/home.html', 'Home'),
    ('CBF/post-home.html', 'General posts'),
    ('CBF/cell.html', 'Cell'),
    ('CBF/about-us.html', 'About-us'),
    ('CBF/thanks.html', 'Gracias'),

]

CMS_PERMISSION = True

CMS_PLACEHOLDER_CONF = {}

DATABASES = dict(default=dj_database_url.config(default=os.environ.get('DATABASE_URL')))

MIGRATION_MODULES = {

}

THUMBNAIL_PROCESSORS = (
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    'filer.thumbnail_processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters'
)

MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'


# CELERY STUFF
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER')
CELERY_RESULT_BACKEND = os.environ.get('CELERY_BROKER_RESULT')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'America/Santo_Domingo'

CELERY_RESULT_BACKEND = 'django-db'


# ANYMAIL PRODUCTION CONFIG
TEMPLATED_EMAIL_BACKEND = 'templated_email.backends.vanilla_django'
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
EMAIL_HOST = os.environ.get('MAILGUN_EMAIL_HOST')
EMAIL_HOST_USER = os.environ.get('MAILGUN_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('MAILGUN_HOST_PASSWORD')
EMAIL_USE_TLS = True
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

ANYMAIL_MAILGUN_API_KEY = os.environ.get('MAILGUN_ACTIVATE_KEY')

MAILGUN_ACCESS_KEY = os.environ.get('MAILGUN_ACTIVATE_KEY')
MAILGUN_SERVER_NAME = os.environ.get('MAILGUN_SENDER_DOMAIN')

# djangocms googlemap

DJANGOCMS_GOOGLEMAP_API_KEY = os.environ.get('GOOGLE_MAP_API_KEY')

# Django newsletter confirmation
NEWSLETTER_CONFIRM_EMAIL = True
NEWSLETTER_EMAIL_DELAY = 0.1


# django-subdomains
# defined in ``SUBDOMAIN_URLCONFS``.
ROOT_URLCONF = 'CBF.urls'

# A dictionary of urlconf module paths, keyed by their subdomain.
SUBDOMAIN_URLCONFS = {
    None: 'CBF.urls',  # no subdomain, e.g. ``example.com``
    'tcd': 'CBF.urls.tcd',
    'tcd.comunidadbiblicadefe': 'CBF.urls.tcd',

}
