"""
Django settings for catshef project.

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

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

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

import os

# 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.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '5td@0hvw*+&j+cd*pk=see!=5^t6x6%!f85dxww*3+1&uw7afx'

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

ALLOWED_HOSTS = []

STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

# local path where the files will be stored
MEDIA_URL = '/media/'
# local path where the files will be stored
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sorl.thumbnail',
    'products',
    'account',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    '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 = (
    # default value
    'django.contrib.auth.backends.ModelBackend',
)

ROOT_URLCONF = 'catshef.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'products.context_processors.site_name',
                'products.context_processors.login_modal_form',
                'account.context_processors.snackbar_data',
                'cart.context_processors.cart',
            ],
        },
    },
]

WSGI_APPLICATION = 'catshef.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

# django.auth settings
LOGIN_URL = '/account/login/'  # TODO: decide on url

# cart app settings
INSTALLED_APPS += [
    'cart',
]
CART_SESSION_ID = 'catshef.cart'

# django-allauth settings
AUTHENTICATION_BACKENDS += (
    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

INSTALLED_APPS += [
    # The Django sites framework is required
    'django.contrib.sites',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    # providers to enable: (uncomment as needed)
    #'allauth.socialaccount.providers.facebook',
    #'allauth.socialaccount.providers.google',
    #'allauth.socialaccount.providers.twitter',
    #'allauth.socialaccount.providers.instagram',
]

SITE_ID = 1

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
# Where to redirect authenticated users when they access login/signup pages 
LOGIN_REDIRECT_URL = '/account/'
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'http'
ACCOUNT_USERNAME_REQUIRED = False
# TODO: return something more appropriate, like the User's name
# TODO: ACCOUNT _SIGNUP_FORM_CLASS = 'something' [http://stackoverflow.com/questions/12303478/how-to-customize-user-profile-when-using-django-allauth]
ACCOUNT_SIGNUP_FORM_CLASS = 'account.forms.SignUpForm'
ACCOUNT_USER_DISPLAY = lambda u: u.email


# django-phonenumber-field settings
INSTALLED_APPS += [
    'phonenumber_field',
]

# django-boostrap3 settings
INSTALLED_APPS += [
    'bootstrap3',
]

# convert messages to SnackBars(toasts, actually)
MIDDLEWARE_CLASSES += [
    'catshef.middleware.mtosmiddleware.MessageToSnackBarMiddleware',
]

"""
# django-nose sttings
INSTALLED_APPS += [
    'django_nose',
]
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
"""
# -- TESTING SETTINGS -- #
# TODO: organize settings files (Issue #56)

FIXTURE_DIRS = (
    os.path.join(BASE_DIR, 'catshef/tests/fixtures/'),
)
# -- END TESTING SETTINGS -- #
