"""
Django settings for arapheno project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/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__+ "/../")))

ADMINS = [tuple(admin.split(':')) for admin in os.getenv('ADMINS', '').split(',')] if os.getenv('ADMINS') else []

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY','REPLACE_WITH_PROD_KEY')


ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS','127.0.0.1').split()

# Application definition

INSTALLED_APPS = [
    'autocomplete_light',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'home',
    'phenotypedb',
    'django_tables2',
    'rest_framework',
    'rest_framework_swagger',
    'widget_tweaks',
    'corsheaders',
]

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
        'rest_framework.permissions.DjangoModelPermissions',
    ],
    'DEFAULT_RENDERER_CLASSES': (
        #'rest_framework.renderers.BrowsableAPIRenderer',
        #can be added if necessary (provides a nice browser interface)
        'rest_framework_csv.renderers.CSVRenderer',
        'rest_framework.renderers.JSONRenderer',
        'phenotypedb.renderer.PLINKRenderer',
    ),
}

MIDDLEWARE_CLASSES = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    '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',
]

ROOT_URLCONF = 'arapheno.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, '../html'), os.path.join(BASE_DIR,'../xml/')],
        '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',
                'phenotypedb.context_processors.version',
            ],
        },
    },
]

WSGI_APPLICATION = 'arapheno.wsgi.application'





# Password validation
# https://docs.djangoproject.com/en/1.9/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.9/topics/i18n/
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = '/srv/static'


STATICFILES_DIRS = [os.path.join(BASE_DIR,'../static'),]

# https://github.com/marcgibbons/django-rest-swagger/issues/220
# Needed to get     request.is_secure() == True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

GITHUB_URL='https://github.com/1001genomes/AraPheno/commit'
DATACITE_PREFIX = '10.21958'
DATACITE_USERNAME = os.environ.get('DATACITE_USERNAME', None)
DATACITE_PASSWORD = os.environ.get('DATACITE_PASSWORD', None)
DATACITE_DOI_URL = 'http://search.datacite.org/works'
DOI_BASE_URL = 'http://arapheno.1001genomes.org'


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
    },
}

CORS_ORIGIN_WHITELIST = (
    'http://www.1001genomes.org',
    'http://aragwas.1001genomes.org',
    'http://localhost:8000',
    'http://localhost:8080',
    'http://127.0.0.1:8080'
)