"""
Django settings for cholera project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
from django.core.urlresolvers import reverse_lazy

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

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

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


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

ALLOWED_HOSTS = []

ADMINS = (
    # ('Your Name', 'your_email@example.com'),
)

MANAGERS = ADMINS

# Application definition

INSTALLED_APPS = (
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.sites",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "betterforms",
    "import_export",
    "surveillance_cholera",
    "django_tables2",
    "djangular",
    "guardian",
    "django_extensions",
    "authtools",
)

MIDDLEWARE_CLASSES = (
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.auth.middleware.SessionAuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    "django.middleware.security.SecurityMiddleware",
)

ROOT_URLCONF = "cholera.urls"


WSGI_APPLICATION = "cholera.wsgi.application"


LANGUAGE_CODE = "en-GB"

TIME_ZONE = "Africa/Bujumbura"

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = "/static/"

STATIC_URL = "/static/"

MEDIA_ROOT = os.path.join(PROJECT_PATH, "media")

MEDIA_URL = "/media/"

STATIC_ROOT = os.path.join(PROJECT_PATH, "static")

KNOWN_PREFIXES = {
    "RG": "SELF_REGISTRATION",
    "ENR": "PATIENT_REGISTRATION",
    "SV": "TRACK",
    "REC": "RECEPTION_P_T",
}

# you better use yours
SECRET_KEY = ")_7av^!cy(wfx=k#3*7x+(=j^fzv+ot^1@sh9s9t=8$bu@r(z$"

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
    }
}

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

FIXTURE_DIRS = (os.path.join(BASE_DIR, "fixtures"),)


TEMPLATE_DIRS = (os.path.join(BASE_DIR, "templates"),)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.template.context_processors.debug",
    "django.template.context_processors.i18n",
    "django.template.context_processors.media",
    "django.core.context_processors.request",
    "django.template.context_processors.static",
    "django.template.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    "surveillance_cholera.context_processors.search_form",
    "surveillance_cholera.context_processors.myfacility",
)

# smartmin
# create the smartmin CRUDL permissions on all objects
PERMISSIONS = {
    "*": (
        "create",  # can create an object
        "read",  # can read an object, viewing it's details
        "update",  # can update an object
        "delete",  # can delete an object,
        "list",
    )  # can view a list of the objects
}

# assigns the permissions that each group should have, here creating an Administrator group with
# authority to create and change users
GROUP_PERMISSIONS = {"Administrator": ("auth.user.*",)}

# -----------------------------------------------------------------------------------
# Login / Logout
# -----------------------------------------------------------------------------------
LOGIN_URL = reverse_lazy("login")
LOGOUT_URL = reverse_lazy("logout")
LOGIN_REDIRECT_URL = reverse_lazy("home")
LOGOUT_REDIRECT_URL = reverse_lazy("home")

# -----------------------------------------------------------------------------------
# Guardian Configuration
# -----------------------------------------------------------------------------------

AUTHENTICATION_BACKENDS = (
    "django.contrib.auth.backends.ModelBackend",
    "guardian.backends.ObjectPermissionBackend",
)

ANONYMOUS_USER_ID = -1

ACCOUNT_ACTIVATION_DAYS = 30

# for e-mail
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

INTERNAL_IPS = "127.0.0.1"

EMAIL_HOST = "smtp.gmail.com"

EMAIL_HOST_USER = "youremail@gmail.com"

EMAIL_HOST_PASSWORD = "abcdefghijklmnopqr"

EMAIL_PORT = 587

EMAIL_USE_TLS = True

SITE_ID = 1

DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

try:
    from localsettings import *
except ImportError:
    pass
