"""
Django settings for NewsPaper project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
from logs.log_config import LOGCONF

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9c=s55m1=+*6l7gto3_8pqcl1^^@!)4)p&f5g2%czp1px*8e(f'

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

ALLOWED_HOSTS = ['np-d.test.com']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
    'news.apps.NewsConfig',
    'accounts',
    'django.contrib.sites',
    'django.contrib.flatpages',
    'fpages',
    'django_filters',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    # ... include the providers you want to enable:
    'allauth.socialaccount.providers.google',
    'django_apscheduler',
]

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',
    
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
]

ROOT_URLCONF = 'NewsPaper.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',
                # `allauth` needs this from django
                'django.template.context_processors.request',
            ],
        },
    },
]

WSGI_APPLICATION = 'NewsPaper.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/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 = [
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',
    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
]

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

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    BASE_DIR / "static"
]

LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/news/'

# The ID, as an integer, of the current site in the django_site database table. 
# This is used so that application data can hook into specific sites and 
# a single database can manage content for multiple sites.
SITE_ID = 1

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'

# The URL (or URL name) to redirect to directly after signing up. Note that users are
# only redirected to this URL if the signup went through uninterruptedly, for example,
# without any side steps due to email verification. If your project requires the user
# to always pass through certain onboarding views after signup, you will have to keep
# track of state indicating whether or not the user successfully onboarded, and
# handle accordingly.
# ACCOUNT_SIGNUP_REDIRECT_URL (=``settings.LOGIN_REDIRECT_URL``)
ACCOUNT_SIGNUP_REDIRECT_URL = '/news/'

# The URL (or URL name) to return to after the user logs out. 
# This is the counterpart to Django’s LOGIN_REDIRECT_URL.
# ACCOUNT_LOGOUT_REDIRECT_URL (=”/”)
ACCOUNT_LOGOUT_REDIRECT_URL ='/news/'

# If redirecting to statically configurable URLs (as specified in your project 
# settings) is not flexible enough, then you can override the following adapter 
# methods:
ACCOUNT_ADAPTER = 'accounts.adapter.MyAccountAdapter'
SOCIALACCOUNT_ADAPTER = 'accounts.adapter.SocialAccountAdapter'
ACCOUNT_FORMS = {'signup': 'accounts.forms.BasicSignupForm'}
# адрес сервера GMAIL
EMAIL_HOST = 'smtp.gmail.com'
# порт smtp сервера тоже одинаковый
EMAIL_PORT = 465
# ваше имя пользователя, например если ваша почта user@yandex.ru, 
# то сюда надо писать user, иными словами, это всё то что идёт до собаки
EMAIL_HOST_USER = 'apustovitin@gmail.com'
EMAIL_HOST_PASSWORD = '' # пароль от почты
EMAIL_USE_SSL = True
SERVER_EMAIL = 'apustovitin@gmail.com'

DEFAULT_FROM_EMAIL = 'apustovitin@gmail.com'
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ADMINS = (
    ('tomusya.g', 'tomusya.g@gmail.com'),
)
# формат даты, которую будет воспрнимать наш задачник(вспоминаем урок по фильтрам) 
APSCHEDULER_DATETIME_FORMAT = "N j, Y, f:s a"

# если задача не выполняется за 25 секунд, то она автоматически снимается, можете поставить время побольше, но как правило, это сильно бьёт по производительности сервера
APSCHEDULER_RUN_NOW_TIMEOUT = 25  # Seconds

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': os.path.join(BASE_DIR, 'cache_files'),
    }
}