"""
Django settings for userprofilesapi project.
Generated by 'django-admin startproject' using Django 2.2.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/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/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'li$ypw%l-n7ko(z7r1pbx2n=cd&bqazrp9)l_hag8tv)++nbrj'
# SECURITY WARNING: don't run with debug turned on in production!

import logging

FORMAT = '%(asctime)-15s %(levelname)s %(module)s %(process)s %(thread)s %(message)s'
logging.basicConfig(filename='error.logs',format=FORMAT, datefmt='%m/%d/%Y %I:%M:%S %p' ,filemode='w')

#logging.basicConfig(filename='error.logs')
#logging.basicConfig(filename='error.logs',filemode='w')

#PRODUZIONE
DEBUG               = True
#ALLOWED_HOSTS       = [ '127.0.0.1','80.211.234.218','localhost','0.0.0.0:8000']
ALLOWED_HOSTS       = ['*']

#SVILUPPO
#DEBUG = False
#ALLOWED_HOSTS = ['*']

# Application definition
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

#    'social_django',    # <-- in test 05 08 2019
#    'admin_view_permission',

    'rest_framework',
    'rest_framework.authtoken',


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

    'rest_auth',
    'rest_auth.registration',

    'webpack_loader',
    'crispy_forms',

#    'users',
    'profiles',
    'events',
    'evidenza',
    'soci',

]

# django-contrib-sites
SITE_ID = 1

MIDDLEWARE = [
    'django.middleware.locale.LocaleMiddleware',
    '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',
#    'social_django.middleware.SocialAuthExceptionMiddleware',
]

ROOT_URLCONF = 'anctradate.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [   os.path.join(BASE_DIR, 'templates'),
                    os.path.join(BASE_DIR, 'events/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',
#                'social_django.context_processors.backends',  # <--
#                'social_django.context_processors.login_redirect', # <--
            ],
        },
    },
]

WSGI_APPLICATION = 'anctradate.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/topics/i18n/


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


LANGUAGE_CODE = 'it'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
LOGIN_URL = "/accounts/login/"
LOGOUT_URL = "/accounts/logout/"

LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

#Dexo Settings------------------------------------------------------------------
#Debug MODE
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static-storage'),
   

#    os.path.join(BASE_DIR, "frontend/dist"),
#    os.path.join(BASE_DIR, "frontend/src/assets"),

#    os.path.join(BASE_DIR, "frontVT/anc-app/dist"),
#    os.path.join(BASE_DIR, "frontVT/anc-app/src/assets"),

    os.path.join(BASE_DIR, "frontIE/anc-app/dist"),
    os.path.join(BASE_DIR, "frontIE/anc-app/src/assets"),

    os.path.join(BASE_DIR, "uploads"),
]

STATIC_ROOT      = os.path.join(os.path.dirname(BASE_DIR), 'static-serve')
MEDIA_ROOT       = os.path.join(os.path.dirname(BASE_DIR), 'media-serve')

#Production
#STATIC_ROOT     = '/home/dexo/static-serve/'        ### collectstatic
#MEDIA_ROOT      = '/home/dexo/media-serve/'

STATIC_URL      = '/static/'                        ### {% static %}
MEDIA_URL       = '/media/'




#test URKEL OK
#MEDIA_URL = '/media/'
#MEDIA_URL = '/home/dexo/media-serve/'
#MEDIA_URL = 'http://localhost/media-serve/'

#MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#MEDIA_ROOT = "uploads"
#MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'uploads')

#Dexo Settings------------------------------------------------------------------

# django-allauth
ACCOUNT_EMAIL_VERIFICATION = "none"
ACCOUNT_EMAIL_REQUIRED = (True)

REST_FRAMEWORK = {

    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),

    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),


    'PAGE_SIZE': 5,
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
}

ADMIN_VIEW_PERMISSION_MODELS = [
    'auth.User',
    'profiles',
    'events',
    'evidenza'
]

#-------------------------------------------------------------------------------

WEBPACK_LOADER = {
    'DEFAULT': {
        'BUNDLE_DIR_NAME': 'dist/',
#        'STATS_FILE':   os.path.join(BASE_DIR, 'frontend', 'webpack-stats.json'),
#        'STATS_FILE':   os.path.join(BASE_DIR, 'frontVT/anc-app', 'webpack-stats.json'),
        'STATS_FILE':   os.path.join(BASE_DIR, 'frontIE/anc-app', 'webpack-stats.json'),
    }
}

# Custom User Model
#AUTH_USER_MODEL = "users.CustomUser"

# django-crispy-forms
CRISPY_TEMPLATE_PACK = "bootstrap4"

ADMINS              = [('mauro','dexa@hotmail.it'),('dexo','pydexo@gmail.com')]
MANAGERS            = ADMINS

# test NG
#EMAIL_HOST          = 'smtp.gmail.com'
#EMAIL_PORT          = 465
#EMAIL_USE_TLS       = False
#EMAIL_USE_SSL       = True
#EMAIL_HOST_USER     = 'pydexo@gmail.com'
#EMAIL_HOST_PASSWORD = 'Maaaaa1234'

# test NG
#EMAIL_HOST          = 'mail9.dominiofaidate.com'
#EMAIL_PORT          = 465
#EMAIL_USE_TLS       = False
#EMAIL_USE_SSL       = True
#EMAIL_HOST_USER     = 'test@2piict.it'
#EMAIL_HOST_PASSWORD = 'testtest'

# test NG
#EMAIL_HOST          = 'smtp.live.com'
#EMAIL_PORT          = 465
#EMAIL_USE_TLS       = False
#EMAIL_USE_SSL       = True
#EMAIL_HOST_USER     = 'pydexa@hotmail.com'
#EMAIL_HOST_PASSWORD = 'TestTest1234'

SERVER_EMAIL        = 'pydexo'
DEFAULT_FROM_EMAIL  = 'pydexa@hotmail.com'
#DEFAULT_TO_EMAIL    = 'pyDexo@gmail.com'

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

# test 2019 11 10
EMAIL_BACKEND       = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST          = 'smtp.gmail.com'
EMAIL_USE_TLS       = True
EMAIL_PORT          = 587
EMAIL_HOST_USER     = 'pydexo@gmail.com'
EMAIL_HOST_PASSWORD = 'Maaaaa1234'

