-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
120 lines (99 loc) · 3.54 KB
/
Copy pathsettings.py
File metadata and controls
120 lines (99 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
BASE_DIR = Path(__file__).resolve().parent
def _read_secrets():
"""secrets.txt sits next to this file, KEY=value per line. See secrets.txt.example."""
secrets = {}
try:
lines = (BASE_DIR / 'secrets.txt').read_text().splitlines()
except FileNotFoundError:
return secrets
for line in lines:
line = line.strip()
if not line or line.startswith('#'):
continue
key, sep, value = line.partition('=')
if sep:
secrets[key.strip()] = value.strip().strip('\'"')
return secrets
SECRETS = _read_secrets()
def setting(name, default=''):
"""Environment wins over secrets.txt, so a deployment can override either way."""
return os.environ.get(name) or SECRETS.get(name, default)
DEBUG = setting('VAMDC_DICT_DEBUG') == '1'
SECRET_KEY = setting('VAMDC_DICT_SECRET_KEY')
if not SECRET_KEY:
if not DEBUG:
raise ImproperlyConfigured(
'No VAMDC_DICT_SECRET_KEY in the environment or in %s'
% (BASE_DIR / 'secrets.txt'))
SECRET_KEY = 'insecure-key-for-local-development-only'
ADMINS = (
('vamdc dictionary', 'thomas.marquart@physics.uu.se'),
)
SERVER_EMAIL = 'vamdc-dict-noreply@neon.physics.uu.se'
DEFAULT_FROM_EMAIL = SERVER_EMAIL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'dict.sqlite',
}
}
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static'
TIME_ZONE = 'Europe/Stockholm'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = False
USE_TZ = True
ROOT_URLCONF = 'urls'
APPEND_SLASH = True
# /new/ posts one id plus one checkbox per dictionary keyword, well past the
# default limit of 1000
DATA_UPLOAD_MAX_NUMBER_FIELDS = 5000
ALLOWED_HOSTS = setting('VAMDC_DICT_HOSTS', '*').split(',')
# Django >= 4 checks the Origin header on POST, so the admin login needs the
# public https origin listed here. Caddy redirects the .org name to .eu, so .eu
# is what browsers actually post from.
CSRF_TRUSTED_ORIGINS = setting('VAMDC_DICT_ORIGINS', 'https://dictionary.vamdc.eu').split(',')
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
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',
],
},
},
]
# the admin is the only write surface, so keep its session off plain http.
# TLS itself (redirect, HSTS) is Caddy's job.
SESSION_COOKIE_SECURE = not DEBUG
CSRF_COOKIE_SECURE = not DEBUG
MIDDLEWARE = (
'django.middleware.security.SecurityMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'browse',
)