"""
Django settings for epyme project.

Generated by 'django-admin startproject' using Django 3.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
from django.urls import reverse_lazy

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).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 = '%4hmo*xy@(i5jzub!+l8l2+6@sia_u77x2lk!kyg=-8_cd@$bu'

# 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',
    'django.contrib.staticfiles',
    'rest_framework',
    'widget_tweaks',
    'apps.core',
    'apps.comun',
    'easyaudit',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    #'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
    'crum.CurrentRequestUserMiddleware',
    'easyaudit.middleware.easyaudit.EasyAuditMiddleware',
]

ROOT_URLCONF = 'epyme.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 = 'epyme.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'epymedb',
        'USER': 'postgres',
        'HOST': 'localhost',
        'PASSWORD': '1234',
        'PORT': '5432',
    }
}

# 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 = 'es-pe'

TIME_ZONE = 'America/Lima'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

SESSION_COOKIE_AGE = 30
SESSION_SAVE_EVERY_REQUEST = True  
SESSION_EXPIRE_AT_BROWSER_CLOSE = True 

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

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

AUTH_USER_MODEL = 'core.User' # new

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

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

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'portal.emype@gmail.com'
EMAIL_HOST_PASSWORD = "%Manco504"
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

LOGIN_URL = '/login'
LOGIN_REDIRECT_URL = '/comun/empview'
LOGOUT_REDIRECT_URL = '/login'


# PROJECT_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir)

# if DEBUG == False:
#     print('local')
#     DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
    
#     STATIC_ROOT = 'staticfiles/'
#     STATIC_URL = '/staticfiles/'
    
#     MEDIA_ROOT = STATIC_ROOT + 'mediafiles'
#     MEDIA_URL = STATIC_URL + 'mediafiles/'
    
#     UPLOAD_ROOT = 'uploads/'
    
#     DOWNLOAD_URL = STATIC_URL + "mediafiles/downloads"
#     DOWNLOAD_ROOT = os.path.join(PROJECT_ROOT, "static/media/downloads")
# # for prod environment
# else: 
#     print('produccion')

#     import os
#     os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="c:\intel\TECOM-c119eb61edc0.json"

#     DEFAULT_FILE_STORAGE = 'gcloud.GoogleCloudMediaFileStorage'
#     STATICFILES_STORAGE = 'gcloud.GoogleCloudStaticFileStorage'
    
#     GS_PROJECT_ID = 'TECOM'
#     GS_STATIC_BUCKET_NAME = 'bucketmype-tecom'
#     GS_MEDIA_BUCKET_NAME = 'bucketmype-tecom'  # same as STATIC BUCKET if using single bucket both for static and media
    
#     STATIC_URL = 'https://storage.googleapis.com/{}/static/staticfiles/'.format(GS_STATIC_BUCKET_NAME)
#     STATIC_ROOT = "static/"

#     MEDIA_URL = 'https://storage.googleapis.com/{}/static/mediafiles/'.format(GS_MEDIA_BUCKET_NAME)
#     MEDIA_ROOT = "media/"
    
#     UPLOAD_ROOT = 'media/uploads/'
    
#     DOWNLOAD_ROOT = os.path.join(PROJECT_ROOT, "static/media/downloads")
#     DOWNLOAD_URL = STATIC_URL + "media/downloads"

    
