diff options
Diffstat (limited to 'pydis_site/settings.py')
-rw-r--r-- | pydis_site/settings.py | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/pydis_site/settings.py b/pydis_site/settings.py new file mode 100644 index 00000000..e8355918 --- /dev/null +++ b/pydis_site/settings.py @@ -0,0 +1,259 @@ +""" +Django settings for pydis_site project. + +Generated by 'django-admin startproject' using Django 2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os +import sys + +import environ + + +env = environ.Env( + DEBUG=(bool, False) +) + + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +DEBUG = env('DEBUG') + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +if DEBUG: + ALLOWED_HOSTS = [ + 'pythondiscord.local', + 'admin.pythondiscord.local', + 'api.pythondiscord.local', + 'staff.pythondiscord.local', + 'wiki.pythondiscord.local' + ] + SECRET_KEY = "+_x00w3e94##2-qm-v(5&-x_@*l3t9zlir1etu+7$@4%!it2##" + +elif 'CI' in os.environ: + ALLOWED_HOSTS = ['*'] + SECRET_KEY = "{©ø¬½.Þ7&Ñ`Q^Kº*~¢j<wxß¾±ðÛJ@q" + +else: + ALLOWED_HOSTS = env.list( + 'ALLOWED_HOSTS', + default=[ + 'pythondiscord.com', + 'admin.pythondiscord.com', + 'api.pythondiscord.com', + 'staff.pythondiscord.local', + 'wiki.pythondiscord.local' + ] + ) + SECRET_KEY = env('SECRET_KEY') + + +# Application definition + +INSTALLED_APPS = [ + 'pydis_site.apps.api', + 'pydis_site.apps.home', + 'pydis_site.apps.wiki', + + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + 'crispy_forms', + 'django_hosts', + 'django_filters', + 'django_crispy_bulma', + 'django_simple_bulma', + 'rest_framework', + 'rest_framework.authtoken' +] + +MIDDLEWARE = [ + 'django_hosts.middleware.HostsRequestMiddleware', + + '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_hosts.middleware.HostsResponseMiddleware', +] +ROOT_URLCONF = 'pydis_site.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'pydis_site', 'templates')], + 'APP_DIRS': True, + 'OPTIONS': { + 'builtins': [ + 'django_hosts.templatetags.hosts_override', + ], + + '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 = 'pydis_site.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 = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.1/howto/static-files/ + +STATIC_URL = '/static/' +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'pydis_site', 'static')] +STATIC_ROOT = env('STATIC_ROOT', default='staticfiles') + +STATICFILES_FINDERS = [ + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + + 'django_simple_bulma.finders.SimpleBulmaFinder', +] + +# django-hosts +# https://django-hosts.readthedocs.io/en/latest/ +ROOT_HOSTCONF = 'pydis_site.hosts' +DEFAULT_HOST = 'home' + +if DEBUG: + PARENT_HOST = 'pythondiscord.local:8000' +else: + PARENT_HOST = env('PARENT_HOST', default='pythondiscord.com') + +# Django REST framework +# http://www.django-rest-framework.org +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.TokenAuthentication', + ), + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.DjangoModelPermissions', + ), + 'TEST_REQUEST_DEFAULT_FORMAT': 'json' +} + + +# Logging +# https://docs.djangoproject.com/en/2.1/topics/logging/ +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'verbose': { + 'format': ( + '%(asctime)s | %(process)d:%(thread)d | %(module)s | %(levelname)-8s | %(message)s' + ) + } + }, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler' + } + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'propagate': True, + 'level': env( + 'LOG_LEVEL', + default=( + # If there is no explicit `LOG_LEVEL` set, + # use `DEBUG` if we're running in debug mode but not + # testing. Use `ERROR` if we're running tests, else + # default to using `WARN`. + 'INFO' + if DEBUG and 'test' not in sys.argv + else ( + 'ERROR' + if 'test' in sys.argv + else 'WARN' + ) + ) + ) + } + } +} + +# Custom settings for Crispyforms +CRISPY_ALLOWED_TEMPLATE_PACKS = ( + "bootstrap", + "uni_form", + "bootstrap3", + "bootstrap4", + "bulma", +) + +CRISPY_TEMPLATE_PACK = "bulma" + +# Custom settings for django-simple-bulma +BULMA_SETTINGS = { + "variables": { + "primary": "#7289DA", + "link": "$primary", + } +} |