import os

# Due to the GDAL
if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/temp'

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

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

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

ALLOWED_HOSTS = ["*"]

os.environ['DJANGO_SETTINGS_MODULE'] = 'airlief.settings'

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.gis',
    'airlief',
    'api',
]

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',
    'django.middleware.cache.FetchFromCacheMiddleware', # Cache middleware
]

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

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

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'airlief',
        'USER': 'airlief',
        'PASSWORD': 'airlief',
        'HOST': '127.0.0.1',
        'PORT': '',

        # 'NAME': os.environ.get('DATABASE_NAME'),
        # 'USER': os.environ.get('DATABASE_USER'),
        # 'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
        # 'HOST': os.environ.get('DATABASE_HOST'),
        # 'PORT': os.environ.get('DATABASE_PORT'),

    },
    'influxDB': {
        'NAME': 'example',
        'USER': 'root',
        'PASSWORD': '<PASSWORD>',
        'HOST': 'localhost',
        'PORT': 8086,
        'MEASUREMENT': 'airquality',

        # 'NAME': os.environ.get('INFLUXDB_NAME'),
        # 'USER': os.environ.get('INFLUXDB_USER'),
        # 'PASSWORD': <PASSWORD>('INFLUXDB_PASSWORD'),
        # 'HOST': os.environ.get('INFLUXDB_HOST'),
        # 'PORT': os.environ.get('INFLUXDB_PORT'),
        # 'MEASUREMENT': os.environ.get('INFLUXDB_MEASUREMENT'),
    }
}

# Redis as backend for Django session data
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

# Cache time to live is 15 minutes.
CACHES = {
    "default": {
        # 'BACKEND': 'django_redis.cache.RedisCache',
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'dev_cache',
        # 'LOCATION': 'redis://127.0.0.1:6379/1',
        'TIMEOUT': 60*60*24*7*4,
        'VERSION': 1,
        "OPTIONS": {
            # 'CLIENT_CLASS": "django_redis.client.DefaultClient',
            'MAX_ENTRIES': 10000,
        },
        "KEY_PREFIX": "cache"
    }
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = False

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

STATIC_URL = '/static/'

# Environment keys

AQICN_API_KEY = os.environ.get('AQICN_API_KEY')
SMOGTOK_API_AUTH = os.environ.get('SMOGTOK_API_AUTH')
AIRTHINGS_API_KEY = os.environ.get('AIRTHINGS_API_KEY')
AIRLY_API_KEY = os.environ.get('AIRLY_API_KEY')


import os

# Due to the GDAL
if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/temp'

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

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

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

ALLOWED_HOSTS = ["*"]

os.environ['DJANGO_SETTINGS_MODULE'] = 'airlief.settings'

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.gis',
    'airlief',
    'api',
]

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',
    'django.middleware.cache.FetchFromCacheMiddleware', # Cache middleware
]

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

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

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'airlief',
        'USER': 'airlief',
        'PASSWORD': 'airlief',
        'HOST': '127.0.0.1',
        'PORT': '',

        # 'NAME': os.environ.get('DATABASE_NAME'),
        # 'USER': os.environ.get('DATABASE_USER'),
        # 'PASSWORD': os.environ.get('DATABASE_PASSWORD'),
        # 'HOST': os.environ.get('DATABASE_HOST'),
        # 'PORT': os.environ.get('DATABASE_PORT'),

    },
    'influxDB': {
        'NAME': 'example',
        'USER': 'root',
        'PASSWORD': '<PASSWORD>',
        'HOST': 'localhost',
        'PORT': 8086,
        'MEASUREMENT': 'airquality',

        # 'NAME': os.environ.get('INFLUXDB_NAME'),
        # 'USER': os.environ.get('INFLUXDB_USER'),
        # 'PASSWORD': <PASSWORD>('INFLUXDB_PASSWORD'),
        # 'HOST': os.environ.get('INFLUXDB_HOST'),
        # 'PORT': os.environ.get('INFLUXDB_PORT'),
        # 'MEASUREMENT': os.environ.get('INFLUXDB_MEASUREMENT'),
    }
}

# Redis as backend for Django session data
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

# Cache time to live is 15 minutes.
CACHES = {
    "default": {
        # 'BACKEND': 'django_redis.cache.RedisCache',
        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
        'LOCATION': 'dev_cache',
        # 'LOCATION': 'redis://127.0.0.1:6379/1',
        'TIMEOUT': 60*60*24*7*4,
        'VERSION': 1,
        "OPTIONS": {
            # 'CLIENT_CLASS": "django_redis.client.DefaultClient',
            'MAX_ENTRIES': 10000,
        },
        "KEY_PREFIX": "cache"
    }
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = False

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

STATIC_URL = '/static/'

# Environment keys

AQICN_API_KEY = os.environ.get('AQICN_API_KEY')
SMOGTOK_API_AUTH = os.environ.get('SMOGTOK_API_AUTH')
AIRTHINGS_API_KEY = os.environ.get('AIRTHINGS_API_KEY')
AIRLY_API_KEY = os.environ.get('AIRLY_API_KEY')


# Due to the GDAL # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECRET_KEY = os.environ.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! # DEBUG = (os.environ.get('DEBUG', False).lower() == 'true') # Application definition # Cache middleware # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases # 'NAME': os.environ.get('DATABASE_NAME'), # 'USER': os.environ.get('DATABASE_USER'), # 'PASSWORD': os.environ.get('DATABASE_PASSWORD'), # 'HOST': os.environ.get('DATABASE_HOST'), # 'PORT': os.environ.get('DATABASE_PORT'), # 'NAME': os.environ.get('INFLUXDB_NAME'), # 'USER': os.environ.get('INFLUXDB_USER'), # 'PASSWORD': <PASSWORD>('INFLUXDB_PASSWORD'), # 'HOST': os.environ.get('INFLUXDB_HOST'), # 'PORT': os.environ.get('INFLUXDB_PORT'), # 'MEASUREMENT': os.environ.get('INFLUXDB_MEASUREMENT'), # Redis as backend for Django session data # Cache time to live is 15 minutes. # 'BACKEND': 'django_redis.cache.RedisCache', # 'LOCATION': 'redis://127.0.0.1:6379/1', # 'CLIENT_CLASS": "django_redis.client.DefaultClient', # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ # Environment keys