"""
Django settings for gobgift project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import environ

ROOT_DIR = environ.Path(__file__) - 3
APPS_DIR = environ.Path('gobgift')
env = environ.Env()
environ.Env.read_env()

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'gqetrtwagztc=oauwb_+jl-2a8k(exh@ly*12nhrd0oiys@!z@'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool('DJANGO_DEBUG', False)

ALLOWED_HOSTS = []

# Application definition

DJANGO_APPS = (
    'dal',
    'dal_select2',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites'
)

THIRD_PARTY_APPS = (
    'coverage',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_framework_swagger',
    'floppyforms',
    'allauth',
    'allauth.account',
    'rest_auth.registration',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'webpack_loader',
    'rest_auth'
)

LOCAL_APPS = (
    'gobgift.core',
    'gobgift.api',
    'gobgift.wishlists',
    'gobgift.gifts',
    'gobgift.groups',
)

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

MIDDLEWARE = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend'
)

SITE_ID = 1

SOCIAL_AUTH_FACEBOOK_KEY = env.str('SOCIAL_AUTH_FACEBOOK_KEY', default='')
SOCIAL_AUTH_FACEBOOK_SECRET = env.str('SOCIAL_AUTH_FACEBOOK_SECRET', default='')

SOCIALACCOUNT_PROVIDERS = {
}

LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/done/'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [str(APPS_DIR.path('templates'))],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': DEBUG,
            'context_processors': [
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.debug",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
            ]
        }
    },
]

ROOT_URLCONF = 'config.urls'

WSGI_APPLICATION = 'config.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': str(ROOT_DIR.path('db.sqlite3')),
    }
}

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

LANGUAGE_CODE = 'fr'

gettext = lambda s: s
LANGUAGES = (
    ('fr', gettext('French')),
    # ('en', gettext('English')),
)

TIME_ZONE = 'America/Montreal'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_ROOT = str(ROOT_DIR.path('static'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    str(APPS_DIR.path('static')),
    str(ROOT_DIR.path('frontend/dist')),
)

MEDIA_ROOT = str(APPS_DIR.path('media'))
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'uni_form'

# Restframework
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    ),
}

WEBPACK_LOADER = {
    'DEFAULT': {
        'BUNDLE_DIR_NAME': 'dist/',
        'STATS_FILE': str(ROOT_DIR.path('webpack-stats.json')),
    }
}


@@ -410,16 +410,17 @@
 bgift')%0A
+%0A
 env = en
@@ -435,29 +435,566 @@
 v()%0A
-environ.Env.read_env(
+%0A# .env file, should load only in development environment%0AREAD_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)%0A%0Aif READ_DOT_ENV_FILE:%0A    # Operating System Environment variables have precedence over variables defined in the .env file,%0A    # that is to say variables from the .env files will only be used if not defined%0A    # as environment variables.%0A    env_file = str(ROOT_DIR.path('.env'))%0A    print('Loading : %7B%7D'.format(env_file))%0A    env.read_env(env_file)%0A    print('The .env file has been loaded. See base.py for more information'
 )%0A%0A#

Change the readenv behavior with .env