"""
Django settings for oeem_energy_datastore 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 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 = os.environ["SECRET_KEY"]

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get("DEBUG","false").lower() == "true"

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sslserver',
    'oauth2_provider',
    'rest_framework',
    'datastore',
)

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',
    'django_pdb.middleware.PdbMiddleware',
)

ROOT_URLCONF = 'oeem_energy_datastore.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',
                'django.core.context_processors.request',
            ],
        },
    },
]

WSGI_APPLICATION = 'oeem_energy_datastore.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {'default': dj_database_url.config()}


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

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.8/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.environ.get("STATIC_ROOT")

OAUTH2_PROVIDER = {
    'SCOPES': {'read': 'Read scope', 'write': 'Write scope'},
    'ACCESS_TOKEN_EXPIRE_SECONDS': 315360000, # 10 years
}

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.ext.rest_framework.OAuth2Authentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    )
}

GRAPPELLI_ADMIN_TITLE = "Open Energy Efficiency Meter"

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s'
        }
    },
    'handlers': {
        'logfile': {
            'level': 'DEBUG',
            'class': 'logging.handlers.WatchedFileHandler',
            'formatter': 'verbose',
            'filename': '/srv/logs/django.log',
        }
    },
    'loggers': {
        'django': {
            'handlers': ['logfile'],
            'level': 'DEBUG',
        },
        'customer_registry.views': {
            'handlers': ['logfile'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}

@@ -1,812 +1,148 @@
-%22%22%22%0ADjango settings for oeem_energy_datastore project.%0A%0AGenerated by 'django-admin startproject' using Django 1.8.2.%0A%0AFor more information on this file, see%0Ahttps://docs.djangoproject.com/en/1.8/topics/settings/%0A%0AFor the full list of settings and their values, see%0Ahttps://docs.djangoproject.com/en/1.8/ref/settings/%0A%22%22%22%0A%0A# Build paths inside the project like this: os.path.join(BASE_DIR, ...)%0Aimport os%0Aimport dj_database_url%0A%0ABASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))%0A%0A%0A# Quick-start development settings - unsuitable for production%0A# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/%0A%0A# SECURITY WARNING: keep the secret key used in production secret!%0ASECRET_KEY = os.environ%5B%22SECRET_KEY%22%5D%0A%0A# SECURITY WARNING: don't run with debug turned on in production!
+import os%0Aimport dj_database_url%0A%0ABASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))%0A%0ASECRET_KEY = os.environ%5B%22SECRET_KEY%22%5D%0A
 %0ADEB
@@ -224,35 +224,8 @@
 '%5D%0A%0A
-%0A# Application definition%0A%0A
 INST
@@ -1712,407 +1712,150 @@
 n'%0A%0A
-%0A# Database%0A# https://docs.djangoproject.com/en/1.8/ref/settings/#databases%0ADATABASES = %7B'default': dj_database_url.config()%7D%0A%0A%0A# Internationalization%0A# https://docs.djangoproject.com/en/1.8/topics/i18n/%0A%0ALANGUAGE_CODE = 'en-us'%0A%0ATIME_ZONE = 'UTC'%0A%0AUSE_I18N = True%0A%0AUSE_L10N = True%0A%0AUSE_TZ = True%0A%0A%0A# Static files (CSS, JavaScript, Images)%0A# https://docs.djangoproject.com/en/1.8/howto/static-files/
+DATABASES = %7B'default': dj_database_url.config()%7D%0A%0ALANGUAGE_CODE = 'en-us'%0A%0ATIME_ZONE = 'UTC'%0A%0AUSE_I18N = True%0A%0AUSE_L10N = True%0A%0AUSE_TZ = True
 %0A%0AST

Clean up settings files