Fix template string syntax, formatting
This commit is contained in:
parent
6ed1025a8d
commit
0702731c7f
2 changed files with 295 additions and 334 deletions
|
@ -1,6 +1,11 @@
|
||||||
""" models that will show up in django admin for superuser """
|
""" Models that will show up in Django admin for superuser """
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
from django . contrib import admin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
admin . site . register ( models . User )
|
admin . site . register ( models . User )
|
||||||
admin . site . register ( models . FederatedServer )
|
admin . site . register ( models . FederatedServer )
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
""" bookwyrm settings and configuration """
|
""" Bookwyrm settings and configuration """
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from django . core . exceptions import ImproperlyConfigured
|
from django . core . exceptions import ImproperlyConfigured
|
||||||
from django . utils . translation import gettext_lazy as _
|
from django . utils . translation import gettext_lazy as _
|
||||||
from environs import Env
|
from environs import Env
|
||||||
|
@ -47,9 +48,7 @@ EMAIL_SENDER = f "{EMAIL_SENDER_NAME}@{EMAIL_SENDER_DOMAIN}"
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR : AnyStr = os . path . dirname ( os . path . dirname ( os . path . abspath (__file__) ) )
|
BASE_DIR : AnyStr = os . path . dirname ( os . path . dirname ( os . path . abspath (__file__) ) )
|
||||||
LOCALE_PATHS = [
|
LOCALE_PATHS = [ os . path . join ( BASE_DIR , "locale" ) ]
|
||||||
os.path.join(BASE_DIR, "locale"),
|
|
||||||
]
|
|
||||||
LANGUAGE_COOKIE_NAME = env . str ( "LANGUAGE_COOKIE_NAME" , "django_language" )
|
LANGUAGE_COOKIE_NAME = env . str ( "LANGUAGE_COOKIE_NAME" , "django_language" )
|
||||||
|
|
||||||
STATIC_ROOT = os . path . join ( BASE_DIR , env ( "STATIC_ROOT" , "static" ) )
|
STATIC_ROOT = os . path . join ( BASE_DIR , env ( "STATIC_ROOT" , "static" ) )
|
||||||
|
@ -78,11 +77,11 @@ FONT_DIR = os.path.join(STATIC_ROOT, "fonts")
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: Don't run with debug turned on in production
|
||||||
DEBUG = env . bool ( "DEBUG" , True )
|
DEBUG = env . bool ( "DEBUG" , True )
|
||||||
USE_HTTPS = env . bool ( "USE_HTTPS" , not DEBUG )
|
USE_HTTPS = env . bool ( "USE_HTTPS" , not DEBUG )
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: Keep the secret key used in production secret
|
||||||
SECRET_KEY = env ("SECRET_KEY")
|
SECRET_KEY = env ("SECRET_KEY")
|
||||||
if not DEBUG and SECRET_KEY == "7(2w1sedok=aznpq)ta1mc4i%4h=xx@hxwx*o57ctsuml0x%fr" :
|
if not DEBUG and SECRET_KEY == "7(2w1sedok=aznpq)ta1mc4i%4h=xx@hxwx*o57ctsuml0x%fr" :
|
||||||
raise ImproperlyConfigured ("You must change the SECRET_KEY env variable")
|
raise ImproperlyConfigured ("You must change the SECRET_KEY env variable")
|
||||||
|
@ -146,39 +145,25 @@ TEMPLATES = [
|
||||||
|
|
||||||
LOG_LEVEL = env ( "LOG_LEVEL" , "INFO" ) . upper ()
|
LOG_LEVEL = env ( "LOG_LEVEL" , "INFO" ) . upper ()
|
||||||
# Override aspects of the default handler to our taste
|
# Override aspects of the default handler to our taste
|
||||||
# See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration
|
# See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration for a reference to the defaults we're overriding
|
||||||
# for a reference to the defaults we're overriding
|
# It seems that in order to override anything you have to include its entire dependency tree (handlers and filters) which makes this a bit verbose
|
||||||
#
|
|
||||||
# It seems that in order to override anything you have to include its
|
|
||||||
# entire dependency tree (handlers and filters) which makes this a
|
|
||||||
# bit verbose
|
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
"version" : 1 ,
|
"version" : 1 ,
|
||||||
"disable_existing_loggers" : False ,
|
"disable_existing_loggers" : False ,
|
||||||
"filters" : {
|
"filters" : {
|
||||||
# These are copied from the default configuration, required for
|
# These are copied from the default configuration, required for implementing mail_admins below
|
||||||
# implementing mail_admins below
|
"require_debug_false" : { "()" : "django.utils.log.RequireDebugFalse" } ,
|
||||||
"require_debug_false": {
|
"require_debug_true": { "()" : "django.utils.log.RequireDebugTrue" } ,
|
||||||
"()": "django.utils.log.RequireDebugFalse",
|
"ignore_missing_variable" : { "()" : "bookwyrm.utils.log.IgnoreVariableDoesNotExist" } ,
|
||||||
},
|
|
||||||
"require_debug_true": {
|
|
||||||
"()": "django.utils.log.RequireDebugTrue",
|
|
||||||
},
|
|
||||||
"ignore_missing_variable": {
|
|
||||||
"()": "bookwyrm.utils.log.IgnoreVariableDoesNotExist",
|
|
||||||
},
|
|
||||||
} ,
|
} ,
|
||||||
"handlers" : {
|
"handlers" : {
|
||||||
# Overrides the default handler to make it log to console
|
# Overrides the default handler to make it log to console regardless of the DEBUG setting (default is to not log to console if DEBUG=False)
|
||||||
# regardless of the DEBUG setting (default is to not log to
|
|
||||||
# console if DEBUG=False)
|
|
||||||
"console" : {
|
"console" : {
|
||||||
"level" : LOG_LEVEL ,
|
"level" : LOG_LEVEL ,
|
||||||
"filters" : [ "ignore_missing_variable" ] ,
|
"filters" : [ "ignore_missing_variable" ] ,
|
||||||
"class" : "logging.StreamHandler" ,
|
"class" : "logging.StreamHandler" ,
|
||||||
},
|
},
|
||||||
# This is copied as-is from the default logger, and is
|
# This is copied as-is from the default logger, and is required for the Django section below
|
||||||
# required for the django section below
|
|
||||||
"mail_admins" : {
|
"mail_admins" : {
|
||||||
"level" : "ERROR" ,
|
"level" : "ERROR" ,
|
||||||
"filters" : [ "require_debug_false" ] ,
|
"filters" : [ "require_debug_false" ] ,
|
||||||
|
@ -186,16 +171,13 @@ LOGGING = {
|
||||||
} ,
|
} ,
|
||||||
} ,
|
} ,
|
||||||
"loggers" : {
|
"loggers" : {
|
||||||
# Install our new console handler for Django's logger, and
|
# Install our new console handler for Django's logger, and override the log level while we're at it
|
||||||
# override the log level while we're at it
|
|
||||||
"django" : {
|
"django" : {
|
||||||
"handlers" : [ "console" , "mail_admins" ] ,
|
"handlers" : [ "console" , "mail_admins" ] ,
|
||||||
"level" : LOG_LEVEL ,
|
"level" : LOG_LEVEL ,
|
||||||
} ,
|
} ,
|
||||||
"django.utils.autoreload": {
|
"django.utils.autoreload" : { "level" : "INFO" } ,
|
||||||
"level": "INFO",
|
# Add a Bookwyrm-specific logger
|
||||||
},
|
|
||||||
# Add a bookwyrm-specific logger
|
|
||||||
"bookwyrm" : {
|
"bookwyrm" : {
|
||||||
"handlers" : [ "console" ] ,
|
"handlers" : [ "console" ] ,
|
||||||
"level" : LOG_LEVEL ,
|
"level" : LOG_LEVEL ,
|
||||||
|
@ -210,16 +192,16 @@ STATICFILES_FINDERS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r"^.+\.[s]{0,1}(?:a|c)ss$"
|
SASS_PROCESSOR_INCLUDE_FILE_PATTERN = r"^.+\.[s]{0,1}(?:a|c)ss$"
|
||||||
# when debug is disabled, make sure to compile themes once with `./bw-dev compile_themes`
|
# When debug is disabled, make sure to compile themes once with `./bw-dev compile_themes`
|
||||||
SASS_PROCESSOR_ENABLED = DEBUG
|
SASS_PROCESSOR_ENABLED = DEBUG
|
||||||
|
|
||||||
# minify css is production but not dev
|
# Minify CSS in production but not dev
|
||||||
if not DEBUG:
|
if not DEBUG:
|
||||||
SASS_OUTPUT_STYLE = "compressed"
|
SASS_OUTPUT_STYLE = "compressed"
|
||||||
|
|
||||||
WSGI_APPLICATION = "bookwyrm.wsgi.application"
|
WSGI_APPLICATION = "bookwyrm.wsgi.application"
|
||||||
|
|
||||||
# redis/activity streams settings
|
# Redis/activity streams settings
|
||||||
REDIS_ACTIVITY_HOST = env ( "REDIS_ACTIVITY_HOST" , "localhost" )
|
REDIS_ACTIVITY_HOST = env ( "REDIS_ACTIVITY_HOST" , "localhost" )
|
||||||
REDIS_ACTIVITY_PORT = env . int ( "REDIS_ACTIVITY_PORT" , 6379 )
|
REDIS_ACTIVITY_PORT = env . int ( "REDIS_ACTIVITY_PORT" , 6379 )
|
||||||
REDIS_ACTIVITY_PASSWORD = requests . utils . quote ( env ( "REDIS_ACTIVITY_PASSWORD" , "" ) )
|
REDIS_ACTIVITY_PASSWORD = requests . utils . quote ( env ( "REDIS_ACTIVITY_PASSWORD" , "" ) )
|
||||||
|
@ -236,9 +218,9 @@ STREAMS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# Search configuration
|
# Search configuration
|
||||||
# total time in seconds that the instance will spend searching connectors
|
# Total time in seconds that the instance will spend searching connectors
|
||||||
SEARCH_TIMEOUT = env . int ( "SEARCH_TIMEOUT" , 8 )
|
SEARCH_TIMEOUT = env . int ( "SEARCH_TIMEOUT" , 8 )
|
||||||
# timeout for a query to an individual connector
|
# Timeout for a query to an individual connector
|
||||||
QUERY_TIMEOUT = env . int ( "INTERACTIVE_QUERY_TIMEOUT" , env . int ( "QUERY_TIMEOUT" , 5 ) )
|
QUERY_TIMEOUT = env . int ( "INTERACTIVE_QUERY_TIMEOUT" , env . int ( "QUERY_TIMEOUT" , 5 ) )
|
||||||
|
|
||||||
# Redis cache backend
|
# Redis cache backend
|
||||||
|
@ -289,18 +271,10 @@ AUTH_USER_MODEL = "bookwyrm.User"
|
||||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{ "NAME" : "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" } ,
|
||||||
"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" } ,
|
||||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -429,15 +403,11 @@ if USE_S3:
|
||||||
# Content Security Policy
|
# Content Security Policy
|
||||||
CSP_DEFAULT_SRC = [
|
CSP_DEFAULT_SRC = [
|
||||||
"'self'" ,
|
"'self'" ,
|
||||||
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}"
|
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}" if AWS_S3_CUSTOM_DOMAIN else None ,
|
||||||
if AWS_S3_CUSTOM_DOMAIN
|
|
||||||
else None,
|
|
||||||
] + CSP_ADDITIONAL_HOSTS
|
] + CSP_ADDITIONAL_HOSTS
|
||||||
CSP_SCRIPT_SRC = [
|
CSP_SCRIPT_SRC = [
|
||||||
"'self'" ,
|
"'self'" ,
|
||||||
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}"
|
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}" if AWS_S3_CUSTOM_DOMAIN else None ,
|
||||||
if AWS_S3_CUSTOM_DOMAIN
|
|
||||||
else None,
|
|
||||||
] + CSP_ADDITIONAL_HOSTS
|
] + CSP_ADDITIONAL_HOSTS
|
||||||
elif USE_AZURE :
|
elif USE_AZURE :
|
||||||
# Azure settings
|
# Azure settings
|
||||||
|
@ -461,20 +431,16 @@ elif USE_AZURE:
|
||||||
} ,
|
} ,
|
||||||
} ,
|
} ,
|
||||||
"exports" : {
|
"exports" : {
|
||||||
"BACKEND": None, # not implemented yet
|
"BACKEND" : None , # Not implemented yet
|
||||||
} ,
|
} ,
|
||||||
}
|
}
|
||||||
# Azure Static settings
|
# Azure Static settings
|
||||||
STATIC_LOCATION = "static"
|
STATIC_LOCATION = "static"
|
||||||
STATIC_URL = (
|
STATIC_URL = ( f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{STATIC_LOCATION}/" )
|
||||||
f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{STATIC_LOCATION}/"
|
|
||||||
)
|
|
||||||
STATIC_FULL_URL = STATIC_URL
|
STATIC_FULL_URL = STATIC_URL
|
||||||
# Azure Media settings
|
# Azure Media settings
|
||||||
MEDIA_LOCATION = "images"
|
MEDIA_LOCATION = "images"
|
||||||
MEDIA_URL = (
|
MEDIA_URL = ( f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{MEDIA_LOCATION}/" )
|
||||||
f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{MEDIA_LOCATION}/"
|
|
||||||
)
|
|
||||||
MEDIA_FULL_URL = MEDIA_URL
|
MEDIA_FULL_URL = MEDIA_URL
|
||||||
# Content Security Policy
|
# Content Security Policy
|
||||||
CSP_DEFAULT_SRC = [ "'self'" , AZURE_CUSTOM_DOMAIN ] + CSP_ADDITIONAL_HOSTS
|
CSP_DEFAULT_SRC = [ "'self'" , AZURE_CUSTOM_DOMAIN ] + CSP_ADDITIONAL_HOSTS
|
||||||
|
@ -490,9 +456,7 @@ else:
|
||||||
} ,
|
} ,
|
||||||
"exports" : {
|
"exports" : {
|
||||||
"BACKEND" : "django.core.files.storage.FileSystemStorage" ,
|
"BACKEND" : "django.core.files.storage.FileSystemStorage" ,
|
||||||
"OPTIONS": {
|
"OPTIONS" : { "location" : "exports" } ,
|
||||||
"location": "exports",
|
|
||||||
},
|
|
||||||
} ,
|
} ,
|
||||||
}
|
}
|
||||||
# Static settings
|
# Static settings
|
||||||
|
@ -507,11 +471,6 @@ else:
|
||||||
|
|
||||||
CSP_INCLUDE_NONCE_IN = [ "script-src" ]
|
CSP_INCLUDE_NONCE_IN = [ "script-src" ]
|
||||||
|
|
||||||
OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None)
|
|
||||||
OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None)
|
|
||||||
OTEL_SERVICE_NAME = env("OTEL_SERVICE_NAME", None)
|
|
||||||
OTEL_EXPORTER_CONSOLE = env.bool("OTEL_EXPORTER_CONSOLE", False)
|
|
||||||
|
|
||||||
TWO_FACTOR_LOGIN_MAX_SECONDS = env . int ( "TWO_FACTOR_LOGIN_MAX_SECONDS" , 60 )
|
TWO_FACTOR_LOGIN_MAX_SECONDS = env . int ( "TWO_FACTOR_LOGIN_MAX_SECONDS" , 60 )
|
||||||
TWO_FACTOR_LOGIN_VALIDITY_WINDOW = env . int ( "TWO_FACTOR_LOGIN_VALIDITY_WINDOW" , 2 )
|
TWO_FACTOR_LOGIN_VALIDITY_WINDOW = env . int ( "TWO_FACTOR_LOGIN_VALIDITY_WINDOW" , 2 )
|
||||||
|
|
||||||
|
@ -519,12 +478,9 @@ HTTP_X_FORWARDED_PROTO = env.bool("SECURE_PROXY_SSL_HEADER", False)
|
||||||
if HTTP_X_FORWARDED_PROTO :
|
if HTTP_X_FORWARDED_PROTO :
|
||||||
SECURE_PROXY_SSL_HEADER = ( "HTTP_X_FORWARDED_PROTO" , "https" )
|
SECURE_PROXY_SSL_HEADER = ( "HTTP_X_FORWARDED_PROTO" , "https" )
|
||||||
|
|
||||||
# Instance Actor for signing GET requests to "secure mode"
|
# Instance Actor for signing GET requests to "secure mode" Mastodon servers.
|
||||||
# Mastodon servers.
|
# Do not change this setting unless you already have an existing user with the same username - in which case you should change it
|
||||||
# Do not change this setting unless you already have an existing
|
|
||||||
# user with the same username - in which case you should change it!
|
|
||||||
INSTANCE_ACTOR_USERNAME = "bookwyrm.instance.actor"
|
INSTANCE_ACTOR_USERNAME = "bookwyrm.instance.actor"
|
||||||
|
|
||||||
# We only allow specifying DATA_UPLOAD_MAX_MEMORY_SIZE in MiB from .env
|
# We only allow specifying DATA_UPLOAD_MAX_MEMORY_SIZE in MiB from .env (note the difference in variable names).
|
||||||
# (note the difference in variable names).
|
|
||||||
DATA_UPLOAD_MAX_MEMORY_SIZE = env . int ( "DATA_UPLOAD_MAX_MEMORY_MiB" , 100 ) << 20
|
DATA_UPLOAD_MAX_MEMORY_SIZE = env . int ( "DATA_UPLOAD_MAX_MEMORY_MiB" , 100 ) << 20
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue