"""
Django settings for blog project.

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

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

# 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 = '@kwire%#-7c5i@d9wst=@eu6ak^6q8#%@i=a7-r+#ne^w61p+)'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',  #new


    # third party  
    'allauth',  #new
    'allauth.account',  #new
    'allauth.socialaccount',   #new
    'allauth.socialaccount.providers.github',   #new
    
    #locals
    'comment_blog',
    'articles',
    'cities',
    'accounts',
    'rest_framework',
    'polls',
    'sendemail.apps.SendemailConfig',  #new 
    'todos',
    'apis',
    'schools',     #models
]

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES' : [
        'rest_framework.permissions.AllowAny',
    ]
}

TIME_ZONE = 'America/New_York' 


AUTH_USER_MODEL = 'accounts.CustomUser'  #new

DEFAULT_FROM_EMAIL = 'bhattarai@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 

AUTHENTICATION_BACKENDS = (
    #Needed login by username in django admin, regardless of a allauth 
    "django.contrib.auth.backends.ModelBackend",

    # allauth specific authentication methods, such as login by email 
    "allauth.account.auth_backends.AuthenticationBackend",
)

SITE_ID = 1 

ACCOUNT_EMAIL_VERIFICATION = 'none'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False 
ACCOUNT_SESSION_REMEMBER = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_UNIQUE_EMAIL = True

# To send actual emails you will need a managed service like SendGrid, mailgun

# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # new
# DEFAULT_FROM_EMAIL = 'will@learndjango.com'
# EMAIL_HOST = 'smtp.sendgrid.net' # new
# EMAIL_HOST_USER = 'apikey' # new
# EMAIL_HOST_PASSWORD = '<sendgrid_password>' # new
# EMAIL_PORT = 587 # new
# EMAIL_USE_TLS = True # new



LOGIN_REDIRECT_URL = "/comment_blog/home"
ACCOUNT_LOGOUT_REDIRECT_URL = "/accounts/login"

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware', # new
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

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

WSGI_APPLICATION = 'blog.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',
    },
]


# 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 = (str(BASE_DIR.joinpath('static')),)  #new
STATIC_ROOT = str(BASE_DIR.joinpath('staticfiles'))  #new 
# STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' # new 
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # new

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

MEDIA_URL = '/media/'




