﻿"""
Django settings for N_Asset project.

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

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
import posixpath

from celery.schedules import crontab
from django.urls import reverse_lazy
#from django.core.urlresolvers import reverse_lazy
# 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 = 'b9578a94-76ea-4936-8cfe-94b039a639ef'

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

INTERNAL_IPS = ('127.0.0.1', 'localhost',)

ALLOWED_HOSTS = ['*', ]


# Application definition

INSTALLED_APPS = [
    'NA_Notifications',
    'social_django',
    'sslserver',
    'app',
    'NA_DataLayer',
    'NA_Domain',
    'NA_Models',
    # Add your apps here to enable them
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
	'django_extensions',
    #'debug_toolbar'
    'rest_framework',
    
]


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',
    'social_django.middleware.SocialAuthExceptionMiddleware',
    #'debug_toolbar.middleware.DebugToolbarMiddleware',
    #'NA_Notifications.middleware.NotificationMiddleware'
]

SESSION_ENGINE = 'app.sessions'

ROOT_URLCONF = 'N_Asset.urls'

AUTH_USER_MODEL = 'NA_Models.NAPrivilege'

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',

                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

WSGI_APPLICATION = 'N_Asset.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
        'OPTIONS': {
            "init_command": "SET sql_mode='STRICT_TRANS_TABLES'",
        }
    },
}


# 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',
    },
]

AUTHENTICATION_BACKENDS = (
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.facebook.FacebookOAuth2',
    'NA_DataLayer.NA_Auth.NA_AuthBackend',
    'django.contrib.auth.backends.ModelBackend',
)


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Jakarta'  # datetime Jakarta

USE_I18N = True

USE_L10N = True
USE_THOUSAND_SEPARATOR = True
USE_TZ = False

DATETIME_FORMAT = [
    '%Y-%m-%d %H:%M:%S'
]

DATE_INPUT_FORMATS = [
    '%d/%m/%Y'
]

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

STATIC_URL = '/static/'

STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['app/static']))

MEDIA_URL = os.path.join(BASE_DIR, 'app/static/NA_User_Image/img/')

MEDIA_ROOT = os.path.join(BASE_DIR, 'app/static/NA_User_Image/UploadImg/')

# this for custom login url e.g: localhost:8000/login?=next/ and the default url is localhost:8000/account?=next .. . :D
LOGIN_URL = reverse_lazy('login')
LOGO_IMAGE = os.path.join(BASE_DIR, 'app/static/NA_User_Image/Logo/')
EMAIL_USE_TLS = True
EMAIL_BACKEND = ''
EMAIL_HOST = ''
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''

FROM_EMAIL = 'noreply@nufarm.com'

SOCIAL_AUTH_FACEBOOK_KEY = ''
SOCIAL_AUTH_FACEBOOK_SECRET = ''

LOGIN_REDIRECT_URL = reverse_lazy('home')

# CELERY STUFF
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Jakarta'

#if DEBUG :
#   MIDDLEWARE_CLASSES += (
#       'debug_toolbar.middleware.DebugToolbarMiddleware',
#   )
#
#   INSTALLED_APPS += (
#       'debug_toolbar',
#   )
#   def custom_show_toolbar(request):
#        return True
#   DEBUG_TOOLBAR_PANELS = [
#       'ddt_request_history.panels.request_history.RequestHistoryPanel',
#       'debug_toolbar.panels.versions.VersionsPanel',
#       'debug_toolbar.panels.timer.TimerPanel',
#       'debug_toolbar.panels.settings.SettingsPanel',
#       'debug_toolbar.panels.headers.HeadersPanel',
#       'debug_toolbar.panels.request.RequestPanel',
#       'debug_toolbar.panels.sql.SQLPanel',
#       'debug_toolbar.panels.staticfiles.StaticFilesPanel',
#       'debug_toolbar.panels.templates.TemplatesPanel',
#       'debug_toolbar.panels.cache.CachePanel',
#       'debug_toolbar.panels.signals.SignalsPanel',
#       'debug_toolbar.panels.logging.LoggingPanel',
#       'debug_toolbar.panels.redirects.RedirectsPanel',
#       'debug_toolbar.panels.profiling.ProfilingPanel',
#   ]
#   DEBUG_TOOLBAR_CONFIG = {
#       'INTERCEPT_REDIRECTS': False,
#       'RESULTS_STORE_SIZE': 100,
#       #'SHOW_TOOLBAR_CALLBACK': custom_show_toolbar,
#       'HIDE_DJANGO_SQL': False,
#       #'TAG': 'div',
#   }
try:
    from .local_settings import *
except (NameError, ImportError):
    pass
