SOITA/config/settings.py

213 lines
5.8 KiB
Python
Raw Normal View History

2021-12-05 13:50:34 +01:00
import json
import os
2021-12-12 11:35:35 +01:00
from datetime import timedelta
2021-12-05 13:50:34 +01:00
"""
Django settings for config project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
secrets = BASE_DIR + "/secrets.json"
with open(secrets) as f:
keys = json.loads(f.read())
def get_secret(setting, keys=keys):
return keys[setting]
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_secret("SECRET_KEY")
2021-12-11 22:01:14 +01:00
EMAIL_ID = get_secret("EMAIL_ID")
EMAIL_SECRET = get_secret("EMAIL_SECRET")
EMAIL_FROM = get_secret("EMAIL_FROM")
2021-12-05 13:50:34 +01:00
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_secret("DEBUG")
ALLOWED_HOSTS = get_secret("ALLOWED_HOSTS")
2021-12-08 19:28:56 +01:00
APPEND_SLASH = False
2021-12-05 13:50:34 +01:00
# Application definition
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
2021-12-19 16:59:24 +01:00
'django.contrib.sessions',
2021-12-05 13:50:34 +01:00
'django.contrib.staticfiles',
"django.contrib.gis",
"rest_framework",
"rest_framework_simplejwt",
2021-12-05 15:23:29 +01:00
"django_extensions",
2021-12-05 13:50:34 +01:00
"users",
"trials",
"answers",
2021-12-12 11:35:35 +01:00
"questions",
"categories"
2021-12-05 13:50:34 +01:00
]
2021-12-19 16:59:24 +01:00
# AUTHENTICATION_BACKENDS = ['config.authh.SettingsBackend']
2021-12-05 13:50:34 +01:00
MIDDLEWARE = [
2021-12-19 16:59:24 +01:00
'django.contrib.sessions.middleware.SessionMiddleware',
2021-12-05 13:50:34 +01:00
'django.middleware.security.SecurityMiddleware',
"corsheaders.middleware.CorsMiddleware",
2021-12-19 16:59:24 +01:00
'django.contrib.auth.middleware.AuthenticationMiddleware',
2021-12-05 13:50:34 +01:00
# "`debug_toolbar.middleware.DebugToolbarMiddleware`",
'django.middleware.common.CommonMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = get_secret("ROOT_URLCONF")
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
2021-12-11 22:01:14 +01:00
'DIRS': [
os.path.join(BASE_DIR, "templates"),
os.path.join(BASE_DIR, "tools/emails/templates")
],
2021-12-05 13:50:34 +01:00
'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 = 'config.wsgi.application'
# User model
AUTH_USER_MODEL = "users.User"
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": get_secret("DB_NAME"),
"USER": get_secret("DB_USER"),
"PASSWORD": get_secret("DB_PASSWORD"),
"HOST": get_secret("DB_HOST"),
"PORT": get_secret("DB_PORT"),
}
}
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": (
2021-12-05 15:23:29 +01:00
"rest_framework.permissions.IsAuthenticated",
2021-12-05 13:50:34 +01:00
),
2021-12-20 19:40:24 +01:00
# "DEFAULT_AUTHENTICATION_CLASSES": (
# "rest_framework_simplejwt.authentication.JWTAuthentication",
# ),
2021-12-05 13:50:34 +01:00
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
"DEFAULT_FILTER_BACKENDS": (
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.SearchFilter",
"rest_framework.filters.OrderingFilter",
),
"NON_FIELD_ERRORS_KEY": "message",
'DEFAULT_THROTTLE_CLASSES': [
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle'
],
'DEFAULT_THROTTLE_RATES': {
'anon': '100/day',
'user': '10000/day'
},
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
DEVELOPMENT = get_secret("DEVELOPMENT")
if not DEVELOPMENT:
REST_FRAMEWORK.update({
"DEFAULT_RENDERER_CLASSES": (
"djangorestframework_camel_case.render.CamelCaseJSONRenderer",
"djangorestframework_camel_case.render.CamelCaseBrowsableAPIRenderer",
),
"DEFAULT_PARSER_CLASSES": (
"djangorestframework_camel_case.parser.CamelCaseJSONParser",
"djangorestframework_camel_case.parser.CamelCaseMultiPartParser",
"djangorestframework_camel_case.parser.CamelCaseFormParser",
),
"JSON_UNDERSCOREIZE": {
"no_underscore_before_number": True,
},
})
2021-12-12 11:35:35 +01:00
SIMPLE_JWT = {
"AUTH_HEADER_TYPES": ("Bearer", ),
'ACCESS_TOKEN_LIFETIME': timedelta(days=365),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}
2021-12-05 13:50:34 +01:00
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/3.1/topics/i18n/
LANGUAGE_CODE = "pl"
TIME_ZONE = "Europe/Warsaw"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = "/static/"
MEDIA_ROOT = "/media/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
STATIC_ROOT = os.path.join(BASE_DIR, "../static")
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = ('content-disposition', 'accept-encoding',
'content-type', 'accept', 'origin', 'authorization')
MEDIA_URL = "/media/"
2021-12-20 19:40:24 +01:00
LOGIN_URL='welcome'
LOGIN_REDIRECT_URL='welcome'