<gh_stars>1-10
"""
Django settings for monitoringdashboard project.

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

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

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

LOGIN_URL = "/admin/"

# Application definition

INSTALLED_APPS = [
    'monitoringdashboard.apps.CustomAdminConfig',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_rq',
    # Apps
    'servers',
    'notifications',
]

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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'monitoringdashboard.urls'

WSGI_APPLICATION = 'monitoringdashboard.wsgi.application'

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/Berlin'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

# 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',
    },
]


"""########################################################################
#######                     DEPLOYMENT                               #####
########################################################################"""

config = {
  key: value for key, value in os.environ.items()
}
SECRET_KEY = config.get("SECRET_KEY")

# Presence of PRODUCTION as environment variable determines
#  if its in development or in production.
production = config.get("PRODUCTION")
if production:
    # production settings
    DEBUG = False
    ALLOWED_HOSTS = ["*"]
else:
    # development/test settings
    DEBUG = True
    ALLOWED_HOSTS = []


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


"""########################################################################
#######             File Handling + Storage                           #####
########################################################################"""

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

STATIC_URL = "/static/"

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


"""########################################################################
#######                    Caching                                    #####
########################################################################"""

redis_host = config.get('REDIS_HOST')
redis_port = config.get('REDIS_PORT')
if DEBUG:
    CACHE_MIDDLEWARE_SECONDS = 0
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'unique-snowflake'
        },
        'rq': {
            'BACKEND': 'redis_cache.cache.RedisCache',
            'LOCATION': '{host}:{port}'.format(host=redis_host, port=redis_port),
            'OPTIONS': {
                'CLIENT_CLASS': 'django_redis.client.DefaultClient',
                'MAX_ENTRIES': 5000,
            },
        },
    }
else:
    CACHE_MIDDLEWARE_SECONDS = 60
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
            'LOCATION': '/var/tmp/django_cache',
            'TIMEOUT': 86400,  # 1 day
            'OPTIONS': {
                'MAX_ENTRIES': 5000
            }
        },
        'rq': {
            'BACKEND': 'redis_cache.cache.RedisCache',
            'LOCATION': '{host}:{port}'.format(host=redis_host, port=redis_port),
            'OPTIONS': {
                'CLIENT_CLASS': 'django_redis.client.DefaultClient',
                'MAX_ENTRIES': 5000,
            },
        },
    }


"""########################################################################
#######                        Queueing of Tasks                     #####
########################################################################"""

DEFAULT_QUEUE = 'default'
HIGH_QUEUE = 'high'
LOW_QUEUE = 'low'
RQ_QUEUES = {
    DEFAULT_QUEUE: {
        'USE_REDIS_CACHE': 'rq',
    },
    HIGH_QUEUE: {
        'USE_REDIS_CACHE': 'rq',
    },
    LOW_QUEUE: {
        'USE_REDIS_CACHE': 'rq',
    },
}
"""
Django settings for monitoringdashboard project.

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

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

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

LOGIN_URL = "/admin/"

# Application definition

INSTALLED_APPS = [
    'monitoringdashboard.apps.CustomAdminConfig',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_rq',
    # Apps
    'servers',
    'notifications',
]

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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'monitoringdashboard.urls'

WSGI_APPLICATION = 'monitoringdashboard.wsgi.application'

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/Berlin'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

# 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',
    },
]


"""########################################################################
#######                     DEPLOYMENT                               #####
########################################################################"""

config = {
  key: value for key, value in os.environ.items()
}
SECRET_KEY = config.get("SECRET_KEY")

# Presence of PRODUCTION as environment variable determines
#  if its in development or in production.
production = config.get("PRODUCTION")
if production:
    # production settings
    DEBUG = False
    ALLOWED_HOSTS = ["*"]
else:
    # development/test settings
    DEBUG = True
    ALLOWED_HOSTS = []


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


"""########################################################################
#######             File Handling + Storage                           #####
########################################################################"""

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

STATIC_URL = "/static/"

STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


"""########################################################################
#######                    Caching                                    #####
########################################################################"""

redis_host = config.get('REDIS_HOST')
redis_port = config.get('REDIS_PORT')
if DEBUG:
    CACHE_MIDDLEWARE_SECONDS = 0
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'unique-snowflake'
        },
        'rq': {
            'BACKEND': 'redis_cache.cache.RedisCache',
            'LOCATION': '{host}:{port}'.format(host=redis_host, port=redis_port),
            'OPTIONS': {
                'CLIENT_CLASS': 'django_redis.client.DefaultClient',
                'MAX_ENTRIES': 5000,
            },
        },
    }
else:
    CACHE_MIDDLEWARE_SECONDS = 60
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
            'LOCATION': '/var/tmp/django_cache',
            'TIMEOUT': 86400,  # 1 day
            'OPTIONS': {
                'MAX_ENTRIES': 5000
            }
        },
        'rq': {
            'BACKEND': 'redis_cache.cache.RedisCache',
            'LOCATION': '{host}:{port}'.format(host=redis_host, port=redis_port),
            'OPTIONS': {
                'CLIENT_CLASS': 'django_redis.client.DefaultClient',
                'MAX_ENTRIES': 5000,
            },
        },
    }


"""########################################################################
#######                        Queueing of Tasks                     #####
########################################################################"""

DEFAULT_QUEUE = 'default'
HIGH_QUEUE = 'high'
LOW_QUEUE = 'low'
RQ_QUEUES = {
    DEFAULT_QUEUE: {
        'USE_REDIS_CACHE': 'rq',
    },
    HIGH_QUEUE: {
        'USE_REDIS_CACHE': 'rq',
    },
    LOW_QUEUE: {
        'USE_REDIS_CACHE': 'rq',
    },
}
Django settings for monitoringdashboard project.  Generated by 'django-admin startproject' using Django 2.2.  For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Application definition # Apps # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators ######################################################################## #######                     DEPLOYMENT                               ##### ######################################################################## # Presence of PRODUCTION as environment variable determines #  if its in development or in production. # production settings # development/test settings # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases ######################################################################## #######             File Handling + Storage                           ##### ######################################################################## ######################################################################## #######                    Caching                                    ##### ######################################################################## # 1 day ######################################################################## #######                        Queueing of Tasks                     ##### ########################################################################