"""
Django settings for zonagurulk project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
from datetime import timedelta
from pathlib import Path
import os
import pymysql

# Build paths inside the project like this: BASE_DIR / 'subdir'.
from django.urls import reverse_lazy

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/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'e5=r49@c2by44tjxyvpx*@4r^#6tm4$ppqoeuc2u7w_0r%d4r9' #'django-insecure-t-$^^wefz5yp(4-9*8vd*=bd_o0!0rtfqhv=@o-+sb+0j%c-r^'

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

ALLOWED_HOSTS = ['zonaguru.id', 'www.zonaguru.id', '38.103.170.146']

SITE_ID = 1
# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'zonaguruapps',
    'import_export',
    'rest_framework',
    'rest_framework.authtoken',
    'django_filters',
    'prose',
	'django_unused_media',
	'axes',
	'easy_thumbnails',
    'tinymce',
]

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',
	'axes.middleware.AxesMiddleware',
]

ROOT_URLCONF = 'zonaguru.urls'

MEDIA_URL: str = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'zonaguruapps/static/')
STATIC_URL = '/static/'

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


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'zogu',
        'USER': 'zonaguru',
        'PASSWORD': '@AbyanZogu#12000', #'@Zon4guru#12000',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}
pymysql.version_info = (2, 2, 8, "final", 0)
pymysql.install_as_MySQLdb()

# Password validation
# https://docs.djangoproject.com/en/5.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',
    },
]


REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated'
    ],
    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}
# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-US'

TIME_ZONE = 'Asia/Jakarta'

USE_I18N = False

USE_TZ = False

DATE_FORMAT = "d M Y"

USE_L10N = False

TIME_INPUT_FORMATS = ('%H:%M',)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# untuk auth user is not active
AUTHENTICATION_BACKENDS = ['axes.backends.AxesStandaloneBackend',
                           'django.contrib.auth.backends.AllowAllUsersModelBackend',
                           'django.contrib.auth.backends.ModelBackend']

THUMBNAIL_ALIASES = {
    '': {
        'avatar': {'size': (600, 400), 'crop': True},
    },
}
THUMBNAIL_EXTENSION = 'jpg'
THUMBNAIL_TRANSPARENCY_EXTENSION = 'png'

#AXES CONFIGURATIONS
AXES_ENABLED = True
AXES_ONLY_ADMIN_SITE = True
AXES_FAILURE_LIMIT = 7
AXES_COOLOFF_TIME = timedelta(minutes=1)
AXES_RESET_ON_SUCCESS = True
AXES_LOCKOUT_TEMPLATE = 'registration/limit_login_admin.html'

# FILE UPLOAD
FILE_UPLOAD_HANDLERS = ['django.core.files.uploadhandler.MemoryFileUploadHandler','django.core.files.uploadhandler.TemporaryFileUploadHandler',]

LOGIN_URL = reverse_lazy('login')

LOGOUT_URL = reverse_lazy('logout')

LOGOUT_REDIRECT_URL = reverse_lazy('login')


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
MAILER_EMAIL_BACKEND = EMAIL_BACKEND
EMAIL_HOST = 'mail.zonaguru.id'
EMAIL_HOST_USER = 'zonaguru.id@zonaguru.id'
EMAIL_HOST_PASSWORD = '@Zon4guru!aktivasi'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

IMPORT_EXPORT_USE_TRANSACTIONS = True

