"""
Django settings for web_ilk project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/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.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'bhf0w0zu!yqqcw81%&*&p@r-8nsqacpj1_42th5la5hsklh=*m'

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

ALLOWED_HOSTS = []
#AUTH_PROFILE_MODULE = 'accounts.UserProfile'

# Application definition

POLLS_APP = 'polls'
POLLS_DIR = os.path.join(BASE_DIR, POLLS_APP)


USERFILES_ROOT = os.path.join(BASE_DIR, 'userfiles')
LOGFILES_ROOT = os.path.join(BASE_DIR, 'logs')


INSTALLED_APPS = [

    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'djangocodemirror',
    'ckeditor',
    'django-npm',
    'rest_framework',
    'multiselectfield'

]

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

#EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
#EMAIL_FILE_PATH = os.path.join(BASE_DIR, "sent_emails")


#EMAIL_HOST = 'localhost'
#EMAIL_PORT = 1025

#EMAIL_HOST_USER = 'yilmazzalperen@gmail.com'
#EMAIL_HOST_PASSWORD = 'mchl.TRNG00'
#EMAIL_USE_TLS = True
#DEFAULT_FROM_EMAIL = 'KodEn Team <noreply@koden.com>'


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
]

ROOT_URLCONF = 'web_ilk.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',
            ],
        },
    },
]

WSGI_APPLICATION = 'web_ilk.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/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.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'polls.validators.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'polls.validators.MinimumLengthValidator',
    },
    {
        'NAME': 'polls.validators.CommonPasswordValidator',
    },
    {
        'NAME': 'polls.validators.NumberValidator',
    },




]


# Internationalization
# https://docs.djangoproject.com/en/1.11/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.11/howto/static-files/

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

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),

]


STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django-npm.npm.finders.NpmFinder'
]


ADMIN_MEDIA_PREFIX = 'static/admin'

CKEDITOR_JQUERY_URL = os.path.join(STATIC_URL, 'js/jquery.min.js')

TEMPLATE_DIRS = (os.path.join(BASE_DIR,  'templates'),)

NPM_ROOT_PATH = os.path.join(BASE_DIR, '.')


NPM_FINDER_USE_CACHE = True
NPM_FILE_PATTERNS = {
    'react': ['react.js'],
    'express': ['lib/*.js', 'index.js']
}

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'full',
        'height': '100%',
        'width': '100%',

    },
}

CODEMIRROR_PATH = os.path.join(STATIC_URL,r"javascript/codemirror")

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s: %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(name)s.%(funcName)s: %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },

        POLLS_APP: {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': os.path.join(LOGFILES_ROOT, '%s.log' % POLLS_APP),
            'formatter': 'verbose',
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        POLLS_APP : {
            'handlers': ['console', POLLS_APP],
            'level': 'DEBUG',
            'propagate': True,
        },

    }
}


