obsolete.computer

multistream/frontend/settings.py

File Type: text/plain

#Django settings for multistream project.

import os, environ

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

env = environ.Env(
    # set casting, default value
    DEPLOYSERVER = (str,'127.0.0.1'),
    DEFAULT_DOMAIN = (str, 'localhost'),
    PRODUCTION_DOMAINS = (list, ['localhost']),
    DEV_ADMINS = (list, ['user@localhost']),
    PROD_ADMINS = (list, ['user@localhost']),
    SECRET_KEY = (str,''),
    DEV_TWITCH_CLIENT_ID = (str,''),
    DEV_TWITCH_CLIENT_SECRET = (str,''),
    PROD_TWITCH_CLIENT_ID = (str,''),
    PROD_TWITCH_CLIENT_SECRET = (str,''),
    RUNNING_ON_DEV = (bool, True),
    DEBUG = (bool,True),
    USE_LIVE_EMBEDS = (bool, False),
    DATABASE_URL = (str, 'sqlite:///db.sqlite3'),
)
# reading .env file
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
RUNNING_ON_DEV = env('RUNNING_ON_DEV')
DEBUG = env('DEBUG')
USE_LIVE_EMBEDS = env('USE_LIVE_EMBEDS')

DEFAULT_DOMAIN = env('DEFAULT_DOMAIN')
PRODUCTION_DOMAINS = env('PRODUCTION_DOMAINS')

if RUNNING_ON_DEV:
    ALLOWED_HOSTS = ["localhost",env('DEPLOYSERVER')]
    ADMINS=[x.split(':') for x in env.list('DEV_ADMINS')]
    TWITCH_CLIENT_ID = env('DEV_TWITCH_CLIENT_ID')
    TWITCH_CLIENT_SECRET = env('DEV_TWITCH_CLIENT_SECRET')

# PRODUCTION SETTINGS BELOW!!!!!!!
else:
    ALLOWED_HOSTS = PRODUCTION_DOMAINS
    ADMINS=[x.split(':') for x in env.list('PROD_ADMINS')]
    TWITCH_CLIENT_ID = env('PROD_TWITCH_CLIENT_ID')
    TWITCH_CLIENT_SECRET = env('PROD_TWITCH_CLIENT_SECRET')

#future support for different player widgets.
VALID_PLAYER_TYPES = ["twitch"]
PLAYER_TYPE = "twitch"
THUMBNAIL_WIDTH=228
THUMBNAIL_HEIGHT=120
CHANNEL_STALE_TIME = 300 #seconds

#Application definition.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'colorfield',
    'frontend',
    'django_extensions',
]

SITE_ID = 1

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

ROOT_URLCONF = 'frontend.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        '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',
                'frontend.context_processors.baseurl',
                'frontend.context_processors.playertype',
                'frontend.context_processors.useliveembeds',
                #'frontend.context_processors.allowedhosts',
                'frontend.context_processors.allowedhosts_json',
                'frontend.context_processors.allowedhosts_parameterized',
            ],
        },
    },
]


WSGI_APPLICATION = 'frontend.wsgi.application'


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

DATABASES = {
    'default': env.db()
}

# Password validation
# https://docs.djangoproject.com/en/2.1/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.1/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.1/howto/static-files/

STATIC_URL = '/static/'

Meta