254 lines
7.5 KiB
Python
254 lines
7.5 KiB
Python
import os
|
|
|
|
from pathlib import Path
|
|
|
|
from .version import get_current_version
|
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
|
|
DJANGO_PROJECT_DIR = os.path.join(BASE_DIR, "src", "newsreader")
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
|
# SECURITY WARNING: don"t run with debug turned on in production!
|
|
DEBUG = True
|
|
|
|
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]
|
|
INTERNAL_IPS = ["127.0.0.1", "localhost"]
|
|
|
|
# Application definition
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"django.forms",
|
|
# third party apps
|
|
"rest_framework",
|
|
"drf_yasg",
|
|
"celery",
|
|
"django_celery_beat",
|
|
"registration",
|
|
"axes",
|
|
# app modules
|
|
"newsreader.accounts",
|
|
"newsreader.utils",
|
|
"newsreader.news",
|
|
"newsreader.news.core",
|
|
"newsreader.news.collection",
|
|
]
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
"axes.backends.AxesBackend",
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
]
|
|
|
|
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",
|
|
"axes.middleware.AxesMiddleware",
|
|
]
|
|
|
|
ROOT_URLCONF = "newsreader.urls"
|
|
|
|
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [os.path.join(DJANGO_PROJECT_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",
|
|
]
|
|
},
|
|
}
|
|
]
|
|
|
|
WSGI_APPLICATION = "newsreader.wsgi.application"
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
"HOST": os.environ.get("POSTGRES_HOST", ""),
|
|
"NAME": os.environ.get("POSTGRES_NAME", "newsreader"),
|
|
"USER": os.environ.get("POSTGRES_USER"),
|
|
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
|
|
}
|
|
}
|
|
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
|
|
"LOCATION": "localhost:11211",
|
|
},
|
|
"axes": {
|
|
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
|
|
"LOCATION": "localhost:11211",
|
|
},
|
|
}
|
|
|
|
# Logging
|
|
# https://docs.djangoproject.com/en/2.2/topics/logging/#configuring-logging
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"filters": {
|
|
"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"},
|
|
"require_debug_true": {"()": "django.utils.log.RequireDebugTrue"},
|
|
},
|
|
"formatters": {
|
|
"timestamped": {
|
|
"()": "django.utils.log.ServerFormatter",
|
|
"format": "[{server_time}] {message}",
|
|
"style": "{",
|
|
},
|
|
"syslog": {
|
|
"class": "logging.Formatter",
|
|
"format": "[newsreader] {message}",
|
|
"style": "{",
|
|
},
|
|
},
|
|
"handlers": {
|
|
"console": {
|
|
"level": "INFO",
|
|
"filters": ["require_debug_true"],
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "timestamped",
|
|
},
|
|
"mail_admins": {
|
|
"level": "ERROR",
|
|
"filters": ["require_debug_false"],
|
|
"class": "django.utils.log.AdminEmailHandler",
|
|
},
|
|
"syslog": {
|
|
"level": "INFO",
|
|
"filters": ["require_debug_false"],
|
|
"class": "logging.handlers.SysLogHandler",
|
|
"formatter": "syslog",
|
|
"address": "/dev/log",
|
|
},
|
|
"syslog_errors": {
|
|
"level": "ERROR",
|
|
"filters": ["require_debug_false"],
|
|
"class": "logging.handlers.SysLogHandler",
|
|
"formatter": "syslog",
|
|
"address": "/dev/log",
|
|
},
|
|
},
|
|
"loggers": {
|
|
"django": {
|
|
"handlers": ["console", "mail_admins", "syslog_errors"],
|
|
"level": "WARNING",
|
|
},
|
|
"django.server": {
|
|
"handlers": ["console", "syslog_errors"],
|
|
"level": "INFO",
|
|
"propagate": False,
|
|
},
|
|
"django.request": {
|
|
"handlers": ["console", "syslog_errors"],
|
|
"level": "INFO",
|
|
"propagate": False,
|
|
},
|
|
"celery": {"handlers": ["syslog", "console"], "level": "INFO"},
|
|
"celery.task": {
|
|
"handlers": ["syslog", "console"],
|
|
"level": "INFO",
|
|
"propagate": False,
|
|
},
|
|
"newsreader": {"handlers": ["syslog", "console"], "level": "INFO"},
|
|
},
|
|
}
|
|
|
|
# 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"},
|
|
]
|
|
|
|
# Authentication user model
|
|
AUTH_USER_MODEL = "accounts.User"
|
|
|
|
LOGIN_REDIRECT_URL = "/"
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
|
LANGUAGE_CODE = "en-us"
|
|
|
|
TIME_ZONE = "Europe/Amsterdam"
|
|
USE_I18N = True
|
|
USE_L10N = True
|
|
USE_TZ = True
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
|
STATIC_URL = "/static/"
|
|
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
|
STATICFILES_DIRS = [os.path.join(DJANGO_PROJECT_DIR, "static")]
|
|
|
|
# https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-STATICFILES_FINDERS
|
|
STATICFILES_FINDERS = [
|
|
"django.contrib.staticfiles.finders.FileSystemFinder",
|
|
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
|
]
|
|
|
|
DEFAULT_FROM_EMAIL = "newsreader@rss.fudiggity.nl"
|
|
|
|
# Project settings
|
|
VERSION = get_current_version()
|
|
|
|
# Reddit integration
|
|
REDDIT_CLIENT_ID = "CLIENT_ID"
|
|
REDDIT_CLIENT_SECRET = "CLIENT_SECRET"
|
|
REDDIT_REDIRECT_URL = "http://127.0.0.1:8000/accounts/settings/reddit/callback/"
|
|
|
|
# Third party settings
|
|
AXES_HANDLER = "axes.handlers.cache.AxesCacheHandler"
|
|
AXES_CACHE = "axes"
|
|
AXES_FAILURE_LIMIT = 5
|
|
AXES_COOLOFF_TIME = 3 # in hours
|
|
AXES_RESET_ON_SUCCESS = True
|
|
|
|
REST_FRAMEWORK = {
|
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
|
"rest_framework.authentication.SessionAuthentication",
|
|
),
|
|
"DEFAULT_PERMISSION_CLASSES": (
|
|
"rest_framework.permissions.IsAuthenticated",
|
|
"newsreader.accounts.permissions.IsOwner",
|
|
),
|
|
"DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
|
|
}
|
|
|
|
SWAGGER_SETTINGS = {
|
|
"LOGIN_URL": "rest_framework:login",
|
|
"LOGOUT_URL": "rest_framework:logout",
|
|
"DOC_EXPANSION": "list",
|
|
}
|
|
|
|
# Celery
|
|
# https://docs.celeryproject.org/en/stable/userguide/configuration.html
|
|
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
|
|
|
|
REGISTRATION_OPEN = True
|
|
REGISTRATION_AUTO_LOGIN = True
|
|
ACCOUNT_ACTIVATION_DAYS = 7
|