# -*- coding: utf-8 -*-
"""
Django settings for moo project.

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

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


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

ALLOWED_HOSTS = []


# Application definition
DEFAULT_GIT_REPO_URL = "https://gitlab.com/bubblehouse/django-moo.git"
DEFAULT_PERMISSIONS = (
    "anything",
    "read",
    "write",
    "entrust",
    "grant",
    "execute",
    "move",
    "transmute",
    "derive",
    "develop",
    "administer",
)

ALLOWED_MODULES = (
    "moo.core",
    "hashlib",
    "string",
    "re"
)

ALLOWED_BUILTINS = (
    "dict",
    "dir",
    "enumerate",
    "getattr",
    "hasattr",
    "list",
    "set",
    "sorted",
    "type",
)

# Here are all our supported prepositions
PREPOSITIONS = [
    ["with", "using"],
    ["at", "to"],
    ["in front of"],
    ["in", "inside", "into", "within"],
    ["on top of", "on", "onto", "upon", "above"],
    ["out of", "from inside", "from"],
    ["over"],
    ["through"],
    ["under", "underneath", "beneath", "below"],
    ["around", "round"],
    ["between", "among"],
    ["behind", "past"],
    ["beside", "by", "near", "next to", "along"],
    ["for", "about"],
    ['is'],
    ["as"],
    ["off", "off of"],
]

OBJECT_SPECIFIER_CHOICES = (("this", "this"), ("any", "any"), ("none", "none"), ("either", "either"))

PREPOSITION_SPECIFIER_CHOICES = (("any", "any"), ("none", "none"))

# When True, Parser.get_verb() issues a single batch query against AncestorCache
# instead of one _lookup_verb() call per search-order object.
# Requires AncestorCache to be migrated and populated (migration 0025).
# Set to False to fall back to the sequential dispatch path.
MOO_BATCH_VERB_DISPATCH = False

# TTL in seconds for cross-session property value caching in get_property().
# Set to 0 to disable (e.g. in test environments where the cache backend is
# in-process and does not reset between test cases).
MOO_PROP_CACHE_TTL = 120

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django_ace",
    "simplesshkey",
    "django_celery_results",
    "django_celery_beat",
    "moo.core",
    "moo.shell",
]

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",
]

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

ROOT_URLCONF = "moo.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [],
        "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 = "moo.wsgi.application"


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

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}


# Cache
# https://docs.djangoproject.com/en/4.2/ref/settings/#caches

CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": "redis://localhost:6379",
    }
}

# 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"

USE_I18N = True

USE_TZ = True


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

STATIC_URL = "admin/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"

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "filters": {
        "require_debug_false": {
            "()": "django.utils.log.RequireDebugFalse",
        },
        "require_debug_true": {
            "()": "django.utils.log.RequireDebugTrue",
        },
    },
    "formatters": {
        "simple": {
            "format": "%(asctime)s: %(levelname)s %(message)s",
        },
    },
    "handlers": {
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "simple",
        },
    },
    "loggers": {
        "": {
            "handlers": ["console"],
            "level": "INFO",
            "propagate": False,
        }
    },
}
