mybuddy/babybuddy/settings/base.py

213 lines
5.2 KiB
Python
Raw Normal View History

2017-08-11 18:32:02 +00:00
import os
2019-04-14 03:09:55 +00:00
from django.utils.translation import gettext_lazy as _
from dotenv import load_dotenv, find_dotenv
2017-08-11 18:32:02 +00:00
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__)
)
)
)
2017-08-11 18:32:02 +00:00
# Environment variables
# Check for and load environment variables from a .env file.
load_dotenv(find_dotenv())
2017-08-11 18:32:02 +00:00
# Required settings
2017-10-23 13:49:09 +00:00
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '*').split(',')
SECRET_KEY = os.environ.get('SECRET_KEY', None)
DEBUG = os.environ.get('DEBUG', False)
2017-10-23 13:49:09 +00:00
# Applications
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/ref/applications/
2017-08-11 18:32:02 +00:00
INSTALLED_APPS = [
2017-08-13 14:48:16 +00:00
'api',
2017-10-22 18:00:42 +00:00
'babybuddy',
2017-08-13 14:48:16 +00:00
'core',
2017-08-18 13:02:31 +00:00
'dashboard',
2017-08-21 23:21:08 +00:00
'reports',
2017-08-13 14:48:16 +00:00
'django_filters',
2017-08-13 14:48:16 +00:00
'rest_framework',
'rest_framework.authtoken',
2017-08-15 20:50:09 +00:00
'widget_tweaks',
'easy_thumbnails',
'storages',
2017-08-13 14:48:16 +00:00
2017-08-11 18:32:02 +00:00
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
# Middleware
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/ref/middleware/
2017-08-11 18:32:02 +00:00
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
2017-08-11 18:32:02 +00:00
'django.contrib.sessions.middleware.SessionMiddleware',
2019-04-14 02:13:14 +00:00
'django.middleware.locale.LocaleMiddleware',
2017-08-11 18:32:02 +00:00
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
# URL dispatcher
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/topics/http/urls/
2017-10-22 18:00:42 +00:00
ROOT_URLCONF = 'babybuddy.urls'
2017-08-11 18:32:02 +00:00
# Templates
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-TEMPLATES
2017-08-11 18:32:02 +00:00
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',
],
},
},
]
# WGSI
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
2017-08-11 18:32:02 +00:00
2017-10-22 18:00:42 +00:00
WSGI_APPLICATION = 'babybuddy.wsgi.application'
2017-08-11 18:32:02 +00:00
# Authentication
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/topics/auth/default/
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/login/'
LOGOUT_REDIRECT_URL = '/login/'
# Timezone
# https://docs.djangoproject.com/en/3.0/topics/i18n/timezones/
2017-08-11 18:32:02 +00:00
USE_TZ = True
2017-08-11 18:32:02 +00:00
TIME_ZONE = os.environ.get('TIME_ZONE', 'Etc/UTC')
2017-08-11 18:32:02 +00:00
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
2017-08-11 18:32:02 +00:00
USE_I18N = True
2017-08-11 18:32:02 +00:00
LANGUAGE_CODE = 'en'
2017-08-11 18:32:02 +00:00
2019-04-14 02:13:14 +00:00
LOCALE_PATHS = [
os.path.join(BASE_DIR, "locale"),
2019-04-14 03:09:55 +00:00
]
LANGUAGES = [
('en', _('English')),
('fr', _('French')),
('de', _('German')),
2020-01-17 03:14:22 +00:00
('es', _('Spanish')),
2019-05-02 18:48:36 +00:00
('sv', _('Swedish')),
2020-01-17 03:42:49 +00:00
('tr', _('Turkish')),
2019-04-14 02:13:14 +00:00
]
2017-08-11 18:32:02 +00:00
# Format localization
# https://docs.djangoproject.com/en/3.0/topics/i18n/formatting/
USE_L10N = True
FORMAT_MODULE_PATH = ['babybuddy.formats']
2017-08-11 18:32:02 +00:00
# Static files (CSS, JavaScript, Images)
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/howto/static-files/
# http://whitenoise.evans.io/en/stable/django.html
2017-08-11 18:32:02 +00:00
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
2017-08-11 18:32:02 +00:00
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
WHITENOISE_ROOT = os.path.join(BASE_DIR, 'static', 'babybuddy', 'root')
# Media files (User uploaded content)
2020-01-19 16:49:45 +00:00
# https://docs.djangoproject.com/en/3.0/topics/files/
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME', None)
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', None)
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', None)
if AWS_STORAGE_BUCKET_NAME:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
THUMBNAIL_DEFAULT_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# Django Rest Framework
2020-01-19 16:49:45 +00:00
# https://www.django-rest-framework.org/
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
],
'DEFAULT_FILTER_BACKENDS': [
'django_filters.rest_framework.DjangoFilterBackend',
],
'DEFAULT_METADATA_CLASS': 'api.metadata.APIMetadata',
'DEFAULT_PAGINATION_CLASS':
'rest_framework.pagination.LimitOffsetPagination',
'DEFAULT_PERMISSION_CLASSES': [
2017-10-22 18:00:42 +00:00
'api.permissions.BabyBuddyDjangoModelPermissions'
],
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
],
'PAGE_SIZE': 100
}
# Baby Buddy configuration
# See README.md#configuration for details about these settings.
BABY_BUDDY = {
'NAP_START_MIN': os.environ.get('NAP_START_MIN', '06:00'),
2017-12-01 23:07:08 +00:00
'NAP_START_MAX': os.environ.get('NAP_START_MAX', '18:00'),
'ALLOW_UPLOADS': os.environ.get('ALLOW_UPLOADS', True)
}