"""
Django settings for CityHopper project.

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

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/, this is also available in our documentation folder

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

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'l+z=7yqa#!b!%=!@+z2c77fld&0)i58ujn*8$0y-wolm!+nwh%'

# SECURITY WARNING: don't run with debug turned on in production! (shows errors)
DEBUG = True
#can select hosts
ALLOWED_HOSTS = []
#id code for google analytics, must be specified in order for it to work
GOOGLE_ANALYTICS = {
    'google_analytics_id': 'UA-153486564-1',
}

# These are a list of all applications installed in this process
INSTALLED_APPS = [
#The actual CityHopperApp itself an its configuration
    'CityHopperApp.apps.CityhopperappConfig',
#The actual UserApp itself an its configuration
    'UsersApp.apps.UsersappConfig',
#This is django's bootstrap and helps to format pages
    'crispy_forms',
#enables admin page for all those who are superusers(admins)
    'django.contrib.admin',
#enables djangos authorisation system
    'django.contrib.auth',
#tracks all models installed in our django project
    'django.contrib.contenttypes',
#lets you store and retrieve arbitrary data on a per-site-visitor basis (sending and recieving of cookies)
    'django.contrib.sessions',
#enables one time flash messages i.e pop up messages
    'django.contrib.messages',
#collects static files from each of your applications (and any other places you specify) into a single location that can easily be served in production.
    'django.contrib.staticfiles',
#ERD Diagram maker
    'django_spaghetti',
#qr package
    'qr_code',
#google_analytics package
    'google_analytics',
#Stripe payment platform package
    'stripe',
#ERD diagram
    'django_extensions',

]
#middleware is a system to globally alter djangos input or output (hook framework)
MIDDLEWARE = [
#provides security enhancements to request and response cycle.
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
#forbids access to users who have been disallowed in addition to URL rewriting (i.e can append / or www.)
    'django.middleware.common.CommonMiddleware',
#protection against cross site reqeust forgery protection
    'django.middleware.csrf.CsrfViewMiddleware',
#Authentication
    'django.contrib.auth.middleware.AuthenticationMiddleware',
#flash message support
    'django.contrib.messages.middleware.MessageMiddleware',
#protection against clickjacking
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
#defines the root URL
ROOT_URLCONF = 'CityHopper.urls'
#defines where settings.py is (this file)
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))
#defines our template folders an location
TEMPLATES = [
    {
#provides access to django templates
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
#sets template directory
        'DIRS': [os.path.join(SETTINGS_PATH, 'templates')],
#app directory
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
#Debug settings
                'django.template.context_processors.debug',
#provides request contexts with variable request (is current http request)
                'django.template.context_processors.request',
#if enabled requestcontext contains 2 variables user &perms(premissions currently logged in user has)
                'django.contrib.auth.context_processors.auth',
#if enabled requestcontect contains 2 variables messages(list of set messages) and default_message_levels (mapping of message levels names)n user has)
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

#points server to wsgi file
WSGI_APPLICATION = 'CityHopper.wsgi.application'


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

DATABASES = {
    'default': {
#database engine used
        'ENGINE': 'django.db.backends.sqlite3',
#database path
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
#enables translation systems
USE_I18N = True
#enables localized formatting of data
USE_L10N = True
#makes the website timezone aware
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
#static file path
STATIC_URL = '/static/'
#media file path
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#media url path
MEDIA_URL='/media/'

#user redirected here on login
LOGIN_REDIRECT_URL = 'cityhopper-home' # call your home page
#imports crispy_forms
CRISPY_TEMPLATE_PACK = 'bootstrap4'

#Django SPAGHETTI_AND_MEATBALLS extracts models and documentation from a projects models.py to build rich, live, interactive entity-relationship diagrams.
#https://django-spaghetti-and-meatballs.readthedocs.io/en/latest/
SPAGHETTI_SAUCE = {
  'apps':['auth','CityHopperApp', 'UsersApp'],
  'show_fields':True,
  'exclude':{'auth':['user'],
             'UsersApp':['Bookings'],
            },
  'show_proxy':True,
}

# Engine to activate session variables
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'

# cache for QR codes as are process intensive
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
    'qr-code': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'qr-code-cache',
        'TIMEOUT': 3600
    }
}

QR_CODE_CACHE_ALIAS = 'qr-code'


from qr_code.qrcode import constants
QR_CODE_URL_PROTECTION = {
    constants.TOKEN_LENGTH: 30,                         # token length for URL protection. Defaults to 20.
    constants.SIGNING_KEY: 'my-secret-signing-key',     # signing key for URL token. Uses SECRET_KEY if not defined.
    constants.SIGNING_SALT: 'my-signing-salt',          # signing salt for URL token.
    constants.ALLOWS_EXTERNAL_REQUESTS_FOR_REGISTERED_USER: True  # Tells whether a registered user can request the QR code URLs from outside a site that uses this app. It can be a boolean value used for any user or a callable that takes a user as parameter. Defaults to False (nobody can access the URL without the signature token).
}

#STRIPE KEYS WHICH ARE USED AS TOKENS
STRIPE_SECRET_KEY = 'sk_test_b7hFfuGB4WeY5ZyPTd4TOhfw005006UKF4'
STRIPE_PUBLISHABLE_KEY = 'pk_test_BcA2jJgEuGKNh5uEKvHsWXnS00Zpg7IQKS'
