import os

from decouple import config, Csv
from dj_database_url import parse as db_url

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=False, cast=bool)

ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv())

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # geodjango
    'django.contrib.gis',
    # third apps
    'django_extensions',
    'test_without_migrations',
    'leaflet',
    'djgeojson',
    'django_activeurl',
    'bootstrap3',
    # my apps
    'geodjango.core',
    'geodjango.basemap',
    'geodjango.zoneamento_urbano',
]

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

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

DATABASES = {
    'default': config('DATABASE_URL', cast=db_url),
}
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'

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

LANGUAGE_CODE = 'pt-br'

USE_THOUSAND_SEPARATOR = True

DECIMAL_SEPARATOR = ','

TIME_ZONE = 'America/Recife'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')

LEAFLET_CONFIG = {
    'DEFAULT_CENTER': (-7.15539974, -36.92504882),
    'DEFAULT_ZOOM': 8,
    'MIN_ZOOM': 1,
    'MAX_ZOOM': 20,
    # 'SPATIAL_EXTENT': (-38.8050881, -8.342963541, -34.75363733, -5.986627918),
    # 'TILES': [],
    'TILES': [('Google Streets', 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
               {'attribution': '&copy; Google', 'maxZoom': 20, 'subdomains': ['mt0', 'mt1', 'mt2', 'mt3']}), (
                  'Google Satélite', 'http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
                  {'attribution': '&copy; Google', 'maxZoom': 20, 'subdomains': ['mt0', 'mt1', 'mt2', 'mt3']})]
}

TEST_RUNNER = 'rainbowtests.test.runner.RainbowDiscoverRunner'
