"""
Django settings for digitalmarket project.

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

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, ...)
import os
import datetime
from configparser import SafeConfigParser

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!
SECRET_KEY = 'r5=z_n2l&)a_vhj(h+b_)0t0yaegu2uy+wk7i+zjy^e&uyesih'

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

ALLOWED_HOSTS = ['localhost', '127.0.0.1', '34.222.108.7']
# ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
    'django.contrib.admindocs',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'django.contrib.sites',
    'accounts',
    'analytics',
    'billing',
    'cart',
    'products',
    'tags',
    'notifications',
    'flows',
    'key',
    'api',
    'hubs.apps.HubsConfig',
    'devices.apps.DevicesConfig',
    #'hubs',
)

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

LOGIN_URL = '/accounts/login/'
AUTH_USER_MODEL = 'accounts.User'
ROOT_URLCONF = 'digitalmarket.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
            ],
        },
    },
]
# TEMPLATE_DIRS = [os.path.join(os.path.dirname(BASE_DIR), "src", "templates")]

WSGI_APPLICATION = 'digitalmarket.wsgi.application'

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

config = SafeConfigParser()
config.read('/code/config.ini')
    

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': config.get('main', 'mysql_db'),
        'USER': config.get('main', 'mysql_name'),
        'PASSWORD': config.get('main', 'mysql_pw'),
        'HOST': config.get('main', 'mysql_host'),
        'PORT': '3306',
    }
}

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#     }
# }
# Django REST framework
# http://www.django-rest-framework.org/
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',

    )
}

# Make JWT Auth the default authentication mechanism for Django
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS':'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    'MAX_PAGE_SIZE': 100,
}

SITE_ID = 1

# Enables django-rest-auth to use JWT tokens instead of regular tokens.
REST_USE_JWT = True
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'US/Pacific'

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/'
DOCS_URL = '/docs/'

# TEAM MANAGERS
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

# TEAM DOESN'T
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn",
                           "staticfiles")  # 'collect files here' #CDN / AWS S3 Bucket/

MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", "media")
DOCS_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", "docs")

PROTECTED_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn", "protected")

USER_SET_EMAIL_PREF = True
if config.get('main', 'email_tls') == "False" or config.get('main', 'email_tls') == False:
    USER_SET_EMAIL_PREF = False
# EMAIL SETUP
EMAIL_USE_TLS = USER_SET_EMAIL_PREF
EMAIL_HOST = config.get('main', 'email_host')
EMAIL_HOST_USER = config.get('main', 'email_user')
EMAIL_HOST_PASSWORD = config.get('main', 'email_pwd')
EMAIL_PORT = 587
