"""
Django settings for ayushtn project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path
import os, configparser
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# reading config file
config = configparser.ConfigParser()
config.read(os.path.join(BASE_DIR, 'prod.env'))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_5yr&+l8i79dy*(lk5j)a-x07%%32%*j282r7+@3z!bwn=npd+'

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

ALLOWED_HOSTS = ['localhost','192.168.1.154', '1.22.234.46','127.0.0.1', 
                 '192.46.209.64','ayushtn-online.in', 'test1.ayushtn-online.in', 'test2.ayushtn-online.in', '192.168.0.153','uat.ayushtn-online.in']
CSRF_TRUSTED_ORIGINS = ['https://test1.ayushtn-online.in', 'https://test2.ayushtn-online.in', 'https://uat.ayushtn-online.in']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # local applications
    #'patient',
    'baseapp',  
    'consult',
    'diagnoses',
    'help',
    'medic',  
    # third party applications
    'ckeditor', # django-ckeditor
     'dbbackup',  # django-dbbackup
    'colorfield', 
    "crispy_forms",
    "crispy_bootstrap4",
    'import_export',
    'django_user_agents',#easy identification of visitor’s browser, OS and device information, including whether the visitor uses a mobile phone, tablet or a touch capable device
    #'rest_framework', # pip install djangorestframework
    'django_forms_bootstrap'    
]

DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
DBBACKUP_STORAGE_OPTIONS = {'location': os.path.join(BASE_DIR, 'baseapp', 'data', 'backup')}

#'/baseapp/data/backup/'Y:\Projects\aayush\ayushtn\baseapp\data\backup
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',
]

ROOT_URLCONF = 'ayushtn.urls'
LOGIN_REDIRECT_URL ='/base/patient/' #base:home'
LOGIN_URL ='/login'# 'page:login'
# LOGIN_REDIRECT_URL ='/home/'
# LOGIN_URL ='/login/'
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 = 'ayushtn.wsgi.application'


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

DATABASES = {
    'defaultsql': {
        
        "init_command": "SET foreign_key_checks = 0;",
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },

    'default': {
            
        "init_command": "SET foreign_key_checks = 0;",
        'ENGINE': 'django.db.backends.mysql',
        'HOST' : config.get('dbdefault','HOST'),
        'NAME' : config.get('dbdefault','NAME'),
        'USER' : config.get('dbdefault','USER'),
        'PASSWORD' : config.get('dbdefault','PASSWORD'),
        'PORT': config.get('dbdefault','PORT'),
        'OPTIONS': {
         #   'read_default_file': 'cred.cnf',
        #   'ssl': {'ca': 'certificates/cacert.pem', 
        #           'cert': 'certificates/client-cert.pem', 
        #           'key': 'certificates/client-key.pem', },
            #'ssl': {'ca':  BASE_DIR / 'certificates/cacert.cert', },
          }    , }
    # 'default': {

    #     'ENGINE': 'django.db.backends.sqlite3',

    #     'NAME': BASE_DIR / 'db.sqlite3',

    # }
}


# Password validation
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

#TIME_ZONE = 'UTC'
TIME_ZONE =  'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
LOGIN_REDIRECT_URL = '/admin/'
STATIC_URL = 'static/'

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# custom settings 
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"

CRISPY_TEMPLATE_PACK = "bootstrap4"
CACHES = {
    'default': {
        #'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        "BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
        'LOCATION': '127.0.0.1:11211',
    }
}
USER_AGENTS_CACHE = 'default'
MIDDLEWARE_CLASSES = (
    # other middlewares...
    'django_user_agents.middleware.UserAgentMiddleware',
)