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 """
|
||||
from django.contrib import admin
|
||||
""" Models that will show up in Django admin for superuser """
|
||||
|
||||
|
||||
|
||||
from bookwyrm import models
|
||||
from django . contrib import admin
|
||||
|
||||
|
||||
|
||||
admin . site . register ( models . User )
|
||||
admin . site . register ( models . FederatedServer )
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
""" bookwyrm settings and configuration """
|
||||
""" Bookwyrm settings and configuration """
|
||||
|
||||
|
||||
|
||||
import os
|
||||
import requests
|
||||
|
||||
from django . core . exceptions import ImproperlyConfigured
|
||||
from django . utils . translation import gettext_lazy as _
|
||||
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, ...)
|
||||
BASE_DIR : AnyStr = os . path . dirname ( os . path . dirname ( os . path . abspath (__file__) ) )
|
||||
LOCALE_PATHS = [
|
||||
os.path.join(BASE_DIR, "locale"),
|
||||
]
|
||||
LOCALE_PATHS = [ os . path . join ( BASE_DIR , "locale" ) ]
|
||||
LANGUAGE_COOKIE_NAME = env . str ( "LANGUAGE_COOKIE_NAME" , "django_language" )
|
||||
|
||||
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
|
||||
# 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 )
|
||||
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")
|
||||
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")
|
||||
|
@ -146,39 +145,25 @@ TEMPLATES = [
|
|||
|
||||
LOG_LEVEL = env ( "LOG_LEVEL" , "INFO" ) . upper ()
|
||||
# Override aspects of the default handler to our taste
|
||||
# See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration
|
||||
# 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
|
||||
# See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration 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
|
||||
LOGGING = {
|
||||
"version" : 1 ,
|
||||
"disable_existing_loggers" : False ,
|
||||
"filters" : {
|
||||
# These are copied from the default configuration, required for
|
||||
# implementing mail_admins below
|
||||
"require_debug_false": {
|
||||
"()": "django.utils.log.RequireDebugFalse",
|
||||
},
|
||||
"require_debug_true": {
|
||||
"()": "django.utils.log.RequireDebugTrue",
|
||||
},
|
||||
"ignore_missing_variable": {
|
||||
"()": "bookwyrm.utils.log.IgnoreVariableDoesNotExist",
|
||||
},
|
||||
# These are copied from the default configuration, required for implementing mail_admins below
|
||||
"require_debug_false" : { "()" : "django.utils.log.RequireDebugFalse" } ,
|
||||
"require_debug_true": { "()" : "django.utils.log.RequireDebugTrue" } ,
|
||||
"ignore_missing_variable" : { "()" : "bookwyrm.utils.log.IgnoreVariableDoesNotExist" } ,
|
||||
} ,
|
||||
"handlers" : {
|
||||
# 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)
|
||||
# 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)
|
||||
"console" : {
|
||||
"level" : LOG_LEVEL ,
|
||||
"filters" : [ "ignore_missing_variable" ] ,
|
||||
"class" : "logging.StreamHandler" ,
|
||||
},
|
||||
# This is copied as-is from the default logger, and is
|
||||
# required for the django section below
|
||||
# This is copied as-is from the default logger, and is required for the Django section below
|
||||
"mail_admins" : {
|
||||
"level" : "ERROR" ,
|
||||
"filters" : [ "require_debug_false" ] ,
|
||||
|
@ -186,16 +171,13 @@ LOGGING = {
|
|||
} ,
|
||||
} ,
|
||||
"loggers" : {
|
||||
# Install our new console handler for Django's logger, and
|
||||
# override the log level while we're at it
|
||||
# Install our new console handler for Django's logger, and override the log level while we're at it
|
||||
"django" : {
|
||||
"handlers" : [ "console" , "mail_admins" ] ,
|
||||
"level" : LOG_LEVEL ,
|
||||
} ,
|
||||
"django.utils.autoreload": {
|
||||
"level": "INFO",
|
||||
},
|
||||
# Add a bookwyrm-specific logger
|
||||
"django.utils.autoreload" : { "level" : "INFO" } ,
|
||||
# Add a Bookwyrm-specific logger
|
||||
"bookwyrm" : {
|
||||
"handlers" : [ "console" ] ,
|
||||
"level" : LOG_LEVEL ,
|
||||
|
@ -210,16 +192,16 @@ STATICFILES_FINDERS = [
|
|||
]
|
||||
|
||||
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
|
||||
|
||||
# minify css is production but not dev
|
||||
# Minify CSS in production but not dev
|
||||
if not DEBUG:
|
||||
SASS_OUTPUT_STYLE = "compressed"
|
||||
|
||||
WSGI_APPLICATION = "bookwyrm.wsgi.application"
|
||||
|
||||
# redis/activity streams settings
|
||||
# Redis/activity streams settings
|
||||
REDIS_ACTIVITY_HOST = env ( "REDIS_ACTIVITY_HOST" , "localhost" )
|
||||
REDIS_ACTIVITY_PORT = env . int ( "REDIS_ACTIVITY_PORT" , 6379 )
|
||||
REDIS_ACTIVITY_PASSWORD = requests . utils . quote ( env ( "REDIS_ACTIVITY_PASSWORD" , "" ) )
|
||||
|
@ -236,9 +218,9 @@ STREAMS = [
|
|||
]
|
||||
|
||||
# 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 )
|
||||
# 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 ) )
|
||||
|
||||
# Redis cache backend
|
||||
|
@ -289,18 +271,10 @@ AUTH_USER_MODEL = "bookwyrm.User"
|
|||
# https://docs.djangoproject.com/en/3.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",
|
||||
},
|
||||
{ "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" } ,
|
||||
]
|
||||
|
||||
|
||||
|
@ -429,15 +403,11 @@ if USE_S3:
|
|||
# Content Security Policy
|
||||
CSP_DEFAULT_SRC = [
|
||||
"'self'" ,
|
||||
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}"
|
||||
if AWS_S3_CUSTOM_DOMAIN
|
||||
else None,
|
||||
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}" if AWS_S3_CUSTOM_DOMAIN else None ,
|
||||
] + CSP_ADDITIONAL_HOSTS
|
||||
CSP_SCRIPT_SRC = [
|
||||
"'self'" ,
|
||||
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}"
|
||||
if AWS_S3_CUSTOM_DOMAIN
|
||||
else None,
|
||||
f"{AWS_S3_URL_PROTOCOL}//{AWS_S3_CUSTOM_DOMAIN}" if AWS_S3_CUSTOM_DOMAIN else None ,
|
||||
] + CSP_ADDITIONAL_HOSTS
|
||||
elif USE_AZURE :
|
||||
# Azure settings
|
||||
|
@ -461,20 +431,16 @@ elif USE_AZURE:
|
|||
} ,
|
||||
} ,
|
||||
"exports" : {
|
||||
"BACKEND": None, # not implemented yet
|
||||
"BACKEND" : None , # Not implemented yet
|
||||
} ,
|
||||
}
|
||||
# Azure Static settings
|
||||
STATIC_LOCATION = "static"
|
||||
STATIC_URL = (
|
||||
f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{STATIC_LOCATION}/"
|
||||
)
|
||||
STATIC_URL = ( f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{STATIC_LOCATION}/" )
|
||||
STATIC_FULL_URL = STATIC_URL
|
||||
# Azure Media settings
|
||||
MEDIA_LOCATION = "images"
|
||||
MEDIA_URL = (
|
||||
f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{MEDIA_LOCATION}/"
|
||||
)
|
||||
MEDIA_URL = ( f"{PROTOCOL}://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/{MEDIA_LOCATION}/" )
|
||||
MEDIA_FULL_URL = MEDIA_URL
|
||||
# Content Security Policy
|
||||
CSP_DEFAULT_SRC = [ "'self'" , AZURE_CUSTOM_DOMAIN ] + CSP_ADDITIONAL_HOSTS
|
||||
|
@ -490,9 +456,7 @@ else:
|
|||
} ,
|
||||
"exports" : {
|
||||
"BACKEND" : "django.core.files.storage.FileSystemStorage" ,
|
||||
"OPTIONS": {
|
||||
"location": "exports",
|
||||
},
|
||||
"OPTIONS" : { "location" : "exports" } ,
|
||||
} ,
|
||||
}
|
||||
# Static settings
|
||||
|
@ -507,11 +471,6 @@ else:
|
|||
|
||||
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_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 :
|
||||
SECURE_PROXY_SSL_HEADER = ( "HTTP_X_FORWARDED_PROTO" , "https" )
|
||||
|
||||
# Instance Actor for signing GET requests to "secure mode"
|
||||
# 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!
|
||||
# Instance Actor for signing GET requests to "secure mode" 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
|
||||
INSTANCE_ACTOR_USERNAME = "bookwyrm.instance.actor"
|
||||
|
||||
# We only allow specifying DATA_UPLOAD_MAX_MEMORY_SIZE in MiB from .env
|
||||
# (note the difference in variable names).
|
||||
# We only allow specifying DATA_UPLOAD_MAX_MEMORY_SIZE in MiB from .env (note the difference in variable names).
|
||||
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