"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.8.2.
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/
"""

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=(!=oae=3vpcivb5hx6#p%k!!#-*0^**o3(62p8=ze^)^ov%s8'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'StatTracker',
    'djcelery',
)


try:
    BROKER_URL=os.environ['REDIS_URL']
except:
    BROKER_URL = 'redis://localhost:6379/0'
try:
    CELERY_RESULT_BACKEND=os.environ['REDIS_URL']
except:
    CELERY_RESULT_BACKEND = BROKER_URL

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


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

DATABASES = {
    "default": dj_database_url.config(
        default='postgres://nsf001:smashthestate@localhost/stattracker'
    )
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'GMT'

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_ROOT = os.path.join(sys.prefix, "var/static")
STATIC_URL = '/static/'

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

STATICFILES_DIRS = [
#    os.path.join(BASE_DIR, 'static'),
]
STATICFILES_FINDERS = (
    #'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'compressor.finders.CompressorFinder',
)

RIOT_URL = {
    'base': 'https://{proxy}.api.pvp.net/api/lol/{region}/{url}',
    'summoner_by_name': 'v{version}/summoner/by-name/{names}',
    'stats_by_id': 'v{version}/stats/by-summoner/{summoner_id}/ranked?season=SEASON{year}',
    'league_by_id': 'v{version}/league/by-summoner/{summoner_id}/entry',
    'match_history_by_id': 'v{version}/matchlist/by-summoner/{summoner_id}?rankedQueues=RANKED_SOLO_5x5&beginIndex={begin}&endIndex={end}',
    'match_by_id': 'v{version}/match/{match_id}',
    # URLs that don't conform to the base
    'current_game_by_id': 'https://{region}.api.pvp.net/observer-mode/rest/consumer/getSpectatorGameInfo/{platformId}/{summoner_id}',
    'featured_games': 'https://{region}.api.pvp.net/observer-mode/rest/featured',
    'version_by_region': 'https://global.api.pvp.net/api/lol/static-data/{region}/v{version}/versions',
    'champion_list': 'https://global.api.pvp.net/api/lol/static-data/{region}/v{version}/champion?dataById=True'
}

RIOT_API_VERSIONS = {
    'league': '2.5',
    'stats': '1.3',
    'summoner': '1.4',
    'match_history': '2.2',
    'match': '2.2',
    'static_data': '1.2'
}

RIOT_REGIONS = {
    'europe_west': 'euw'
}

RIOT_API_KEY = os.environ.get('RIOT_API_KEY', default='')

try:
    from .local_settings import *
except ImportError:
    pass
