/
settings.py
429 lines (320 loc) · 14.2 KB
/
settings.py
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
# pylint: disable=line-too-long
"""
Django settings for dev project.
Generated by 'django-admin startproject' using Django 1.11.15.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
from misago import load_plugin_list_if_exists
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Define placeholder gettext function
# This function will mark strings in settings visible to makemessages
# without need for Django's i18n features be initialized first.
_ = lambda s: s
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "1znyfpwp*_#!r0#l248lht*6)_0b+504n*2-8cxf(2u)fhi0f^"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# A list of strings representing the host/domain names that this Django site can serve.
# If you are unsure, just enter here your domain name, eg. ['mysite.com', 'www.mysite.com']
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "0.0.0.0"]
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
"default": {
# Misago requires PostgreSQL to run
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("POSTGRES_DB"),
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"HOST": os.environ.get("POSTGRES_HOST"),
"PORT": 5432,
}
}
# Caching
# https://docs.djangoproject.com/en/1.11/topics/cache/#setting-up-the-cache
CACHES = {
"default": {
# Misago doesn't run well with LocMemCache in production environments
"BACKEND": "django.core.cache.backends.locmem.LocMemCache"
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
"OPTIONS": {"user_attributes": ["username", "email"]},
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {"min_length": 7},
},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = "/static/"
# User uploads (Avatars, Attachments, files uploaded in other Django apps, ect.)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
MEDIA_URL = "/media/"
# The absolute path to the directory where collectstatic will collect static files for deployment.
# https://docs.djangoproject.com/en/1.11/ref/settings/#static-root
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# Absolute filesystem path to the directory that will hold user-uploaded files.
# https://docs.djangoproject.com/en/1.11/ref/settings/#media-root
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# This setting defines the additional locations the staticfiles app will traverse if the FileSystemFinder finder
# is enabled, e.g. if you use the collectstatic or findstatic management command or use the static file serving view.
# https://docs.djangoproject.com/en/1.10/ref/settings/#staticfiles-dirs
STATICFILES_DIRS = []
# Email configuration
# https://docs.djangoproject.com/en/1.11/ref/settings/#email-backend
EMAIL_HOST = "localhost"
EMAIL_PORT = 25
# If either of these settings is empty, Django won't attempt authentication.
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
# Default email address to use for various automated correspondence from the site manager(s).
DEFAULT_FROM_EMAIL = "Forums <%s>" % EMAIL_HOST_USER
# Application definition
AUTH_USER_MODEL = "misago_users.User"
AUTHENTICATION_BACKENDS = ["misago.users.authbackends.MisagoBackend"]
CSRF_FAILURE_VIEW = "misago.core.errorpages.csrf_failure"
PLUGINS_LIST_PATH = os.path.join(os.path.dirname(BASE_DIR), "plugins.txt")
INSTALLED_PLUGINS = load_plugin_list_if_exists(PLUGINS_LIST_PATH) or []
INSTALLED_APPS = INSTALLED_PLUGINS + [
# Misago overrides for Django core feature
"misago",
"misago.users",
# Django apps
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.postgres",
"django.contrib.humanize",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# 3rd party apps used by Misago
"ariadne.contrib.django",
"celery",
"debug_toolbar",
"mptt",
"rest_framework",
"social_django",
# Misago apps
"misago.admin",
"misago.acl",
"misago.analytics",
"misago.cache",
"misago.core",
"misago.conf",
"misago.icons",
"misago.themes",
"misago.markup",
"misago.legal",
"misago.categories",
"misago.threads",
"misago.readtracker",
"misago.search",
"misago.socialauth",
"misago.graphql",
"misago.faker",
"misago.menus",
"misago.sso",
"misago.plugins",
]
INTERNAL_IPS = ["127.0.0.1"]
LOGIN_REDIRECT_URL = "misago:index"
LOGIN_URL = "misago:login"
LOGOUT_URL = "misago:logout"
MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
"misago.users.middleware.RealIPMiddleware",
"misago.core.middleware.FrontendContextMiddleware",
"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",
"misago.cache.middleware.cache_versions_middleware",
"misago.conf.middleware.dynamic_settings_middleware",
"misago.socialauth.middleware.socialauth_providers_middleware",
"misago.users.middleware.UserMiddleware",
"misago.acl.middleware.user_acl_middleware",
"misago.core.middleware.ExceptionHandlerMiddleware",
"misago.users.middleware.OnlineTrackerMiddleware",
"misago.admin.middleware.AdminAuthMiddleware",
"misago.threads.middleware.UnreadThreadsCountMiddleware",
]
ROOT_URLCONF = "devproject.urls"
SOCIAL_AUTH_STRATEGY = "misago.socialauth.strategy.MisagoStrategy"
SOCIAL_AUTH_PIPELINE = (
# Steps required by social pipeline to work - don't delete those!
"social_core.pipeline.social_auth.social_details",
"social_core.pipeline.social_auth.social_uid",
"social_core.pipeline.social_auth.social_user",
# If enabled in admin panel, lets your users to associate their old forum account
# with social one, if both have same e-mail address.
"misago.socialauth.pipeline.associate_by_email",
# Those steps make sure banned users may not join your site or use banned name or email.
"misago.socialauth.pipeline.validate_ip_not_banned",
"misago.socialauth.pipeline.validate_user_not_banned",
# Reads user data received from social site and tries to create valid and available username
# Required if you want automatic account creation to work. Otherwise optional.
"misago.socialauth.pipeline.get_username",
# Uncomment next line to enable automatic account creation if data from social site is valid
# and get_username found valid name for new user account:
# 'misago.socialauth.pipeline.create_user',
# This step asks user to complete simple, pre filled registration form containing username,
# email, legal note if you remove it without adding custom one, users will have no fallback
# for joining your site using their social account.
"misago.socialauth.pipeline.create_user_with_form",
# Steps finalizing social authentication flow - don't delete those!
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"misago.socialauth.pipeline.require_activation",
)
SOCIAL_AUTH_POSTGRES_JSONFIELD = True
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.request",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"misago.acl.context_processors.user_acl",
"misago.conf.context_processors.conf",
"misago.conf.context_processors.og_image",
"misago.core.context_processors.misago_version",
"misago.core.context_processors.request_path",
"misago.core.context_processors.momentjs_locale",
"misago.icons.context_processors.icons",
"misago.search.context_processors.search_providers",
"misago.themes.context_processors.theme",
"misago.legal.context_processors.legal_links",
"misago.menus.context_processors.menus",
"misago.users.context_processors.user_links",
"misago.core.context_processors.hooks",
# Data preloaders
"misago.conf.context_processors.preload_settings_json",
"misago.core.context_processors.current_link",
"misago.markup.context_processors.preload_api_url",
"misago.threads.context_processors.preload_threads_urls",
"misago.users.context_processors.preload_user_json",
"misago.socialauth.context_processors.preload_socialauth_json",
# Note: keep frontend_context processor last for previous processors
# to be able to expose data UI app via request.frontend_context
"misago.core.context_processors.frontend_context",
]
},
}
]
WSGI_APPLICATION = "devproject.wsgi.application"
# Django Debug Toolbar
# http://django-debug-toolbar.readthedocs.io/en/stable/configuration.html
DEBUG_TOOLBAR_PANELS = [
"debug_toolbar.panels.versions.VersionsPanel",
"debug_toolbar.panels.timer.TimerPanel",
"debug_toolbar.panels.settings.SettingsPanel",
"debug_toolbar.panels.headers.HeadersPanel",
"debug_toolbar.panels.request.RequestPanel",
"debug_toolbar.panels.sql.SQLPanel",
"misago.acl.panels.MisagoACLPanel",
"debug_toolbar.panels.staticfiles.StaticFilesPanel",
"debug_toolbar.panels.templates.TemplatesPanel",
"debug_toolbar.panels.cache.CachePanel",
"debug_toolbar.panels.signals.SignalsPanel",
"debug_toolbar.panels.logging.LoggingPanel",
]
# Django Rest Framework
# http://www.django-rest-framework.org/api-guide/settings/
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": [
"misago.core.rest_permissions.IsAuthenticatedOrReadOnly"
],
"DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer"],
"EXCEPTION_HANDLER": "misago.core.exceptionhandler.handle_api_exception",
"UNAUTHENTICATED_USER": "misago.users.models.AnonymousUser",
"URL_FORMAT_OVERRIDE": None,
}
# Celery - Distributed Task Queue
# http://docs.celeryproject.org/en/latest/userguide/configuration.html
# Configure Celery to use Redis as message broker.
CELERY_BROKER_URL = "redis://redis:6379/0"
# Celery workers may leak the memory, eventually depriving the instance of resources.
# This setting forces celery to stop worker, clean after it and create new one
# after worker has processed 10 tasks.
CELERY_WORKER_MAX_TASKS_PER_CHILD = 10
# Misago specific settings
# https://misago.readthedocs.io/en/latest/developers/settings.html
# On dev instance, generate only three sizes of avatars instead of default 6 sizes.
MISAGO_AVATARS_SIZES = [400, 200, 100]
# PostgreSQL text search configuration to use in searches
# Defaults to "simple", for list of installed configurations run "\dF" in "psql".
# Standard configs as of PostgreSQL 9.5 are: dutch, english, finnish, french,
# german, hungarian, italian, norwegian, portuguese, romanian, russian, simple,
# spanish, swedish and turkish
# Example on adding custom language can be found here: https://github.com/lemonskyjwt/plpstgrssearch
MISAGO_SEARCH_CONFIG = "simple"
# Path to the directory that Misago should use to prepare user data downloads.
# Should not be accessible from internet.
MISAGO_USER_DATA_DOWNLOADS_WORKING_DIR = os.path.join(BASE_DIR, "userdata")
# Path to directory containing avatar galleries
# Those galleries can be loaded by running loadavatargallery command
MISAGO_AVATAR_GALLERY = os.path.join(BASE_DIR, "avatargallery")
# Profile fields
MISAGO_PROFILE_FIELDS = [
{
"name": _("Personal"),
"fields": [
"misago.users.profilefields.default.RealNameField",
"misago.users.profilefields.default.GenderField",
"misago.users.profilefields.default.BioField",
"misago.users.profilefields.default.LocationField",
],
},
{
"name": _("Contact"),
"fields": [
"misago.users.profilefields.default.TwitterHandleField",
"misago.users.profilefields.default.SkypeIdField",
"misago.users.profilefields.default.WebsiteField",
],
},
{
"name": _("IP address"),
"fields": ["misago.users.profilefields.default.JoinIpField"],
},
]
# Set dev instance to send e-mails to console
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Display debug toolbar if IN_MISAGO_DOCKER enviroment var is set to "1"
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": "misago.conf.debugtoolbar.enable_debug_toolbar"
}