forked from Princeton-CDH/cdh-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
470 lines (410 loc) · 12.8 KB
/
base.py
File metadata and controls
470 lines (410 loc) · 12.8 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
"""
Django settings for cdhweb.
"""
from pathlib import Path
#########
# PATHS #
#########
# Build paths inside the project like this: BASE_DIR / 'subdir'.
# called from cdh-web/cdhweb/settings/__init__.py
# do NOT import this module directly, the path will be different
PROJECT_APP_PATH = Path(__file__).resolve().parent.parent
PROJECT_APP = PROJECT_APP_PATH.name
# base dir is one level up
BASE_DIR = PROJECT_APP_PATH.parent
# Every cache key will get prefixed with this value - here we set it to
# the name of the directory the project is in to try and use something
# project specific.
CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT_APP
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = "/static/"
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = BASE_DIR / STATIC_URL.strip("/")
# Additional locations of static files
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
STATICFILES_DIRS = ()
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = "/media/"
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = BASE_DIR / MEDIA_URL.strip("/")
########################
# MAIN DJANGO SETTINGS #
########################
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
TIME_ZONE = "America/New_York"
# If you set this to True, Django will use timezone-aware datetimes.
USE_TZ = True
# turn off internationalization for now
USE_I18N = False
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en"
# Supported languages
LANGUAGES = (("en", "English"),)
# A boolean that turns on/off debug mode. When set to ``True``, stack traces
# are displayed for error pages. Should always be set to ``False`` in
# production. Best set to ``True`` in local_settings.py
DEBUG = False
# Whether a user's session cookie expires when the Web browser is closed.
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = False
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"django_cas_ng.backends.CASBackend",
)
# The numeric mode to set newly-uploaded files to. The value should be
# a mode you'd pass directly to os.chmod.
FILE_UPLOAD_PERMISSIONS = 0o644
# username for documenting database changes made by code
SCRIPT_USERNAME = "script"
#############
# DATABASES #
#############
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "cdhweb",
"USER": "cdhweb",
"PASSWORD": "",
"HOST": "",
"PORT": "",
}
}
# Increase file upload size to roughly 50 MB
FILEBROWSER_MAX_UPLOAD_SIZE = 50000000
# Use local node-sass installed via npm
COMPRESS_PRECOMPILERS = (("text/x-scss", "node_modules/.bin/sass {infile} {outfile}"),)
# Use local postcss-cli and autoprefixer installed via npm
COMPRESS_AUTOPREFIXER_BINARY = "node_modules/postcss-cli/bin/postcss"
COMPRESS_CSS_FILTERS = (
"compressor.filters.css_default.CssAbsoluteFilter",
# NOTE: requires COMPRESS_ENABLED = True when DEBUG is True
"django_compressor_autoprefixer.AutoprefixerFilter",
)
# use content hashing to ensure same url on both servers
COMPRESS_CSS_HASHING_METHOD = "content"
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# other finders..
"compressor.finders.CompressorFinder",
)
# Package/module name to import the root urlpatterns from for the project.
ROOT_URLCONF = "%s.urls" % PROJECT_APP
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"OPTIONS": {
"loaders": [
"apptemplates.Loader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.static",
"django.template.context_processors.media",
"django.template.context_processors.request",
"django.template.context_processors.tz",
# "wagtail.contrib.settings.context_processors.settings",
# "wagtailmenus.context_processors.wagtailmenus",
"cdhweb.context_extras",
"cdhweb.context_processors.template_settings",
"cdhweb.pages.context_processors.page_intro",
"cdhweb.pages.context_processors.site_search",
],
},
},
]
################
# APPLICATIONS #
################
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.messages",
"django.contrib.postgres",
"django.contrib.redirects",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.sitemaps",
"django.contrib.staticfiles",
"django.contrib.humanize",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
# required to avoid https://github.com/wagtail/wagtail/issues/1824
"wagtail.contrib.search_promotions",
"wagtail.contrib.typed_table_block",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
"wagtail.snippets",
"wagtail.documents",
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail_modeladmin",
"wagtail",
"wagtailmenus",
"wagtailautocomplete",
"modelcluster",
"taggit",
"adminsortable2",
"compressor",
"fullurl",
"django_cas_ng",
"wagtailcodeblock",
"pucas",
"springkit",
# local apps
"cdhweb.projects",
"cdhweb.people",
"cdhweb.events",
"cdhweb.blog",
"cdhweb.pages",
]
# List of middleware classes to use. Order is important; in the request phase,
# these middleware classes will be applied in the order given, and in the
# response phase the middleware will be applied in reverse order.
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.BrokenLinkEmailsMiddleware",
# Uncomment if using internationalisation or localisation
# 'django.middleware.locale.LocaleMiddleware',
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# pucas configuration that is not expected to change across deploys
# and does not reference local server configurations or fields
PUCAS_LDAP = {
# attributes expected by init_profile_from_ldap method
"ATTRIBUTES": [
"uid",
"universityid",
"pustatus",
"ou",
"givenName",
"sn",
"mail",
"telephoneNumber",
"street",
"title",
"displayName",
],
"ATTRIBUTE_MAP": {
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
},
# local method to populate profile fields based on available
# ldap information
"EXTRA_USER_INIT": "cdhweb.people.models.init_person_from_ldap",
}
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": "/var/tmp/django_cache",
}
}
####################
# WAGTAIL SETTINGS #
####################
# Human-readable name of your Wagtail site shown on login to the Wagtail admin.
# https://docs.wagtail.io/en/latest/reference/settings.html#site-name
WAGTAIL_SITE_NAME = "CDH Website"
# base url to wagtail, for use in notification emails
WAGTAILADMIN_BASE_URL = "https://cdh.princeton.edu/cms/"
# Tags are case-sensitive by default. In many cases the reverse is preferable.
# https://docs.wagtail.io/en/latest/reference/settings.html#case-insensitive-tags
TAGGIT_CASE_INSENSITIVE = True
# Shows where a particular image, document or snippet is being used on your site.
# Generates a query which may run slowly on sites with large numbers of pages.
# https://docs.wagtail.io/en/latest/reference/settings.html#usage-for-images-documents-and-snippets
# NOTE: handled by reference index starting in wagtail 4.1
WAGTAIL_USAGE_COUNT_ENABLED = True
# Use Wagtail's postgresql search backend.
# https://docs.wagtail.io/en/latest/reference/contrib/postgres_search.html
WAGTAILSEARCH_BACKENDS = {
"default": {
"BACKEND": "wagtail.search.backends.database",
"SEARCH_CONFIG": "english",
},
}
# enable feature detection in images
WAGTAILIMAGES_FEATURE_DETECTION_ENABLED = True
# custom document model
WAGTAILDOCS_DOCUMENT_MODEL = "cdhpages.LocalAttachment"
# custom embed finders
WAGTAILEMBEDS_FINDERS = [
{"class": "wagtail.embeds.finders.oembed"},
{"class": "cdhweb.pages.embed_finders.GlitchHubEmbedFinder"},
]
WAGTAILIMAGES_WEBP_QUALITY = 80
WAGTAILIMAGES_FORMAT_CONVERSIONS = {
"avif": "avif",
"gif": "gif",
"bmp": "webp",
"jpeg": "webp",
"png": "webp",
"webp": "webp",
}
# List of allowed tags in the rich text editor (tinyMCE). We need to add the
# HTML5 <figcaption>, as it's not included by default.
#
RICHTEXT_ALLOWED_TAGS = [
"a",
"abbr",
"acronym",
"address",
"area",
"article",
"aside",
"b",
"bdo",
"big",
"blockquote",
"br",
"button",
"caption",
"center",
"cite",
"code",
"col",
"colgroup",
"dd",
"del",
"dfn",
"dir",
"div",
"dl",
"dt",
"em",
"fieldset",
"figure",
"figcaption",
"font",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"header",
"hr",
"i",
"img",
"input",
"ins",
"kbd",
"label",
"legend",
"li",
"map",
"men",
"nav",
"ol",
"optgroup",
"option",
"p",
"pre",
"q",
"s",
"samp",
"section",
"select",
"small",
"span",
"strike",
"strong",
"sub",
"sup",
"table",
"tbody",
"td",
"textarea",
"tfoot",
"th",
"thead",
"tr",
"tt",
"",
"ul",
"var",
"wbr",
"iframe",
]
WAGTAIL_CODE_BLOCK_THEME = "coy"
WAGTAIL_CODE_BLOCK_LANGUAGES = (
# default
("bash", "Bash/Shell"),
("css", "CSS"),
("diff", "diff"),
("html", "HTML"),
("javascript", "Javascript"),
("json", "JSON"),
("python", "Python"),
("scss", "SCSS"),
("yaml", "YAML"),
# extras
("django", "Django/Jinja2"),
("git", "Git"),
("go", "Go"),
("markup", "Markup + HTML + XML + SVG + MathML"),
("r", "R"),
)
# Support embedding content from Princeton's Media Central (Kaltura MediaSpace)
# See https://knowledge.kaltura.com/help/mediaspace-oembed-integration
media_central_provider = {
"endpoint": "https://mediacentral.princeton.edu/oembed",
"urls": (
r"^https://mediacentral\.princeton\.edu/id/(?:\w+)\?width=\d+&height=\d+&playerId=\d+$",
r"^https://mediacentral\.princeton\.edu/media/[^/]+/(?:\w+)$",
),
}
# These will be tried in order; we put the Media Central one first so that the
# custom provider will be used. See:
# https://docs.wagtail.io/en/stable/advanced_topics/embeds.html#customising-the-provider-list
WAGTAILEMBEDS_FINDERS = [
{
"class": "wagtail.embeds.finders.oembed",
"providers": [media_central_provider],
},
{
"class": "wagtail.embeds.finders.oembed",
},
{"class": "cdhweb.pages.embed_finders.GlitchHubEmbedFinder"},
]
# list of optional features to enable/disable via configuration
# currently supported: purple-mode
FEATURE_FLAGS = []
# Springkit Settings
BILINGUAL_HEADINGS = False
BILINGUAL_LINKS = False