settings.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. # pylint: disable=line-too-long
  2. """
  3. Django settings for dev project.
  4. Generated by 'django-admin startproject' using Django 1.11.15.
  5. For more information on this file, see
  6. https://docs.djangoproject.com/en/1.11/topics/settings/
  7. For the full list of settings and their values, see
  8. https://docs.djangoproject.com/en/1.11/ref/settings/
  9. """
  10. import os
  11. from misago import load_plugin_list_if_exists
  12. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  13. BASE_DIR = os.path.dirname(os.path.abspath(__file__))
  14. # Define placeholder gettext function
  15. # This function will mark strings in settings visible to makemessages
  16. # without need for Django's i18n features be initialized first.
  17. _ = lambda s: s
  18. # Quick-start development settings - unsuitable for production
  19. # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
  20. # SECURITY WARNING: keep the secret key used in production secret!
  21. SECRET_KEY = "1znyfpwp*_#!r0#l248lht*6)_0b+504n*2-8cxf(2u)fhi0f^"
  22. # SECURITY WARNING: don't run with debug turned on in production!
  23. DEBUG = True
  24. # A list of strings representing the host/domain names that this Django site can serve.
  25. # If you are unsure, just enter here your domain name, eg. ['mysite.com', 'www.mysite.com']
  26. ALLOWED_HOSTS = ["*"]
  27. # Database
  28. # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
  29. DATABASES = {
  30. "default": {
  31. # Misago requires PostgreSQL to run
  32. "ENGINE": "django.db.backends.postgresql",
  33. "NAME": os.environ.get("POSTGRES_DB"),
  34. "USER": os.environ.get("POSTGRES_USER"),
  35. "PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
  36. "HOST": os.environ.get("POSTGRES_HOST"),
  37. "PORT": 5432,
  38. }
  39. }
  40. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  41. # Caching
  42. # https://docs.djangoproject.com/en/1.11/topics/cache/#setting-up-the-cache
  43. CACHES = {
  44. "default": {
  45. # Misago doesn't run well with LocMemCache in production environments
  46. "BACKEND": "django.core.cache.backends.locmem.LocMemCache"
  47. }
  48. }
  49. # Password validation
  50. # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
  51. AUTH_PASSWORD_VALIDATORS = [
  52. {
  53. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  54. "OPTIONS": {"user_attributes": ["username", "email"]},
  55. },
  56. {
  57. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  58. "OPTIONS": {"min_length": 7},
  59. },
  60. {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
  61. {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
  62. ]
  63. # Internationalization
  64. # https://docs.djangoproject.com/en/1.11/topics/i18n/
  65. LANGUAGE_CODE = os.environ.get("LANGUAGE_CODE", "") or "en-us"
  66. TIME_ZONE = "UTC"
  67. USE_I18N = True
  68. USE_L10N = True
  69. USE_TZ = True
  70. # Static files (CSS, JavaScript, Images)
  71. # https://docs.djangoproject.com/en/1.11/howto/static-files/
  72. STATIC_URL = "/static/"
  73. # User uploads (Avatars, Attachments, files uploaded in other Django apps, ect.)
  74. # https://docs.djangoproject.com/en/1.11/howto/static-files/
  75. MEDIA_URL = "/media/"
  76. # The absolute path to the directory where collectstatic will collect static files for deployment.
  77. # https://docs.djangoproject.com/en/1.11/ref/settings/#static-root
  78. STATIC_ROOT = os.path.join(BASE_DIR, "static")
  79. # Absolute filesystem path to the directory that will hold user-uploaded files.
  80. # https://docs.djangoproject.com/en/1.11/ref/settings/#media-root
  81. MEDIA_ROOT = os.path.join(BASE_DIR, "media")
  82. # This setting defines the additional locations the staticfiles app will traverse if the FileSystemFinder finder
  83. # is enabled, e.g. if you use the collectstatic or findstatic management command or use the static file serving view.
  84. # https://docs.djangoproject.com/en/1.10/ref/settings/#staticfiles-dirs
  85. STATICFILES_DIRS = []
  86. # Email configuration
  87. # https://docs.djangoproject.com/en/1.11/ref/settings/#email-backend
  88. EMAIL_HOST = "localhost"
  89. EMAIL_PORT = 25
  90. # If either of these settings is empty, Django won't attempt authentication.
  91. EMAIL_HOST_USER = ""
  92. EMAIL_HOST_PASSWORD = ""
  93. # Default email address to use for various automated correspondence from the site manager(s).
  94. DEFAULT_FROM_EMAIL = "Forums <%s>" % EMAIL_HOST_USER
  95. # Application definition
  96. AUTH_USER_MODEL = "misago_users.User"
  97. AUTHENTICATION_BACKENDS = ["misago.users.authbackends.MisagoBackend"]
  98. CSRF_FAILURE_VIEW = "misago.core.errorpages.csrf_failure"
  99. PLUGINS_LIST_PATH = os.path.join(os.path.dirname(BASE_DIR), "plugins.txt")
  100. INSTALLED_PLUGINS = load_plugin_list_if_exists(PLUGINS_LIST_PATH) or []
  101. INSTALLED_APPS = INSTALLED_PLUGINS + [
  102. # Misago overrides for Django core feature
  103. "misago",
  104. "misago.users",
  105. # Django apps
  106. "django.contrib.admin",
  107. "django.contrib.auth",
  108. "django.contrib.contenttypes",
  109. "django.contrib.postgres",
  110. "django.contrib.humanize",
  111. "django.contrib.sessions",
  112. "django.contrib.messages",
  113. "django.contrib.staticfiles",
  114. # 3rd party apps used by Misago
  115. "ariadne_django",
  116. "celery",
  117. "debug_toolbar",
  118. "mptt",
  119. "rest_framework",
  120. "social_django",
  121. # Misago apps
  122. "misago.admin",
  123. "misago.acl",
  124. "misago.analytics",
  125. "misago.cache",
  126. "misago.core",
  127. "misago.conf",
  128. "misago.icons",
  129. "misago.themes",
  130. "misago.markup",
  131. "misago.legal",
  132. "misago.categories",
  133. "misago.threads",
  134. "misago.readtracker",
  135. "misago.search",
  136. "misago.oauth2",
  137. "misago.socialauth",
  138. "misago.graphql",
  139. "misago.faker",
  140. "misago.menus",
  141. "misago.plugins",
  142. ]
  143. INTERNAL_IPS = ["127.0.0.1"]
  144. LOGIN_REDIRECT_URL = "misago:index"
  145. LOGIN_URL = "misago:login"
  146. LOGOUT_URL = "misago:logout"
  147. MIDDLEWARE = [
  148. "debug_toolbar.middleware.DebugToolbarMiddleware",
  149. "misago.users.middleware.RealIPMiddleware",
  150. "misago.core.middleware.FrontendContextMiddleware",
  151. "django.middleware.security.SecurityMiddleware",
  152. "django.contrib.sessions.middleware.SessionMiddleware",
  153. "django.middleware.common.CommonMiddleware",
  154. "django.middleware.csrf.CsrfViewMiddleware",
  155. "django.contrib.auth.middleware.AuthenticationMiddleware",
  156. "django.contrib.messages.middleware.MessageMiddleware",
  157. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  158. "misago.cache.middleware.cache_versions_middleware",
  159. "misago.conf.middleware.dynamic_settings_middleware",
  160. "misago.socialauth.middleware.socialauth_providers_middleware",
  161. "misago.users.middleware.UserMiddleware",
  162. "misago.acl.middleware.user_acl_middleware",
  163. "misago.core.middleware.ExceptionHandlerMiddleware",
  164. "misago.users.middleware.OnlineTrackerMiddleware",
  165. "misago.admin.middleware.AdminAuthMiddleware",
  166. "misago.threads.middleware.UnreadThreadsCountMiddleware",
  167. ]
  168. ROOT_URLCONF = "devproject.urls"
  169. SECURE_REFERRER_POLICY = "strict-origin-when-cross-origin"
  170. SOCIAL_AUTH_STRATEGY = "misago.socialauth.strategy.MisagoStrategy"
  171. SOCIAL_AUTH_PIPELINE = (
  172. # Steps required by social pipeline to work - don't delete those!
  173. "social_core.pipeline.social_auth.social_details",
  174. "social_core.pipeline.social_auth.social_uid",
  175. "social_core.pipeline.social_auth.social_user",
  176. # If enabled in admin panel, lets your users to associate their old forum account
  177. # with social one, if both have same e-mail address.
  178. "misago.socialauth.pipeline.associate_by_email",
  179. # Those steps make sure banned users may not join your site or use banned name or email.
  180. "misago.socialauth.pipeline.validate_ip_not_banned",
  181. "misago.socialauth.pipeline.validate_user_not_banned",
  182. # Reads user data received from social site and tries to create valid and available username
  183. # Required if you want automatic account creation to work. Otherwise optional.
  184. "misago.socialauth.pipeline.get_username",
  185. # Uncomment next line to enable automatic account creation if data from social site is valid
  186. # and get_username found valid name for new user account:
  187. # 'misago.socialauth.pipeline.create_user',
  188. # This step asks user to complete simple, pre filled registration form containing username,
  189. # email, legal note if you remove it without adding custom one, users will have no fallback
  190. # for joining your site using their social account.
  191. "misago.socialauth.pipeline.create_user_with_form",
  192. # Steps finalizing social authentication flow - don't delete those!
  193. "social_core.pipeline.social_auth.associate_user",
  194. "social_core.pipeline.social_auth.load_extra_data",
  195. "misago.socialauth.pipeline.require_activation",
  196. )
  197. SOCIAL_AUTH_JSONFIELD_ENABLED = True
  198. TEMPLATES = [
  199. {
  200. "BACKEND": "django.template.backends.django.DjangoTemplates",
  201. "DIRS": [],
  202. "APP_DIRS": True,
  203. "OPTIONS": {
  204. "context_processors": [
  205. "django.template.context_processors.debug",
  206. "django.template.context_processors.i18n",
  207. "django.template.context_processors.media",
  208. "django.template.context_processors.request",
  209. "django.template.context_processors.static",
  210. "django.template.context_processors.tz",
  211. "django.contrib.auth.context_processors.auth",
  212. "django.contrib.messages.context_processors.messages",
  213. "misago.acl.context_processors.user_acl",
  214. "misago.conf.context_processors.conf",
  215. "misago.conf.context_processors.og_image",
  216. "misago.core.context_processors.misago_version",
  217. "misago.core.context_processors.request_path",
  218. "misago.core.context_processors.momentjs_locale",
  219. "misago.icons.context_processors.icons",
  220. "misago.search.context_processors.search_providers",
  221. "misago.themes.context_processors.theme",
  222. "misago.legal.context_processors.legal_links",
  223. "misago.menus.context_processors.menus",
  224. "misago.users.context_processors.user_links",
  225. "misago.core.context_processors.hooks",
  226. # Data preloaders
  227. "misago.conf.context_processors.preload_settings_json",
  228. "misago.core.context_processors.current_link",
  229. "misago.markup.context_processors.preload_api_url",
  230. "misago.threads.context_processors.preload_threads_urls",
  231. "misago.users.context_processors.preload_user_json",
  232. "misago.socialauth.context_processors.preload_socialauth_json",
  233. # Note: keep frontend_context processor last for previous processors
  234. # to be able to expose data UI app via request.frontend_context
  235. "misago.core.context_processors.frontend_context",
  236. ]
  237. },
  238. }
  239. ]
  240. WSGI_APPLICATION = "devproject.wsgi.application"
  241. # Django Debug Toolbar
  242. # http://django-debug-toolbar.readthedocs.io/en/stable/configuration.html
  243. DEBUG_TOOLBAR_PANELS = [
  244. "debug_toolbar.panels.versions.VersionsPanel",
  245. "debug_toolbar.panels.timer.TimerPanel",
  246. "debug_toolbar.panels.settings.SettingsPanel",
  247. "debug_toolbar.panels.headers.HeadersPanel",
  248. "debug_toolbar.panels.request.RequestPanel",
  249. "debug_toolbar.panels.sql.SQLPanel",
  250. "misago.acl.panels.MisagoACLPanel",
  251. "debug_toolbar.panels.staticfiles.StaticFilesPanel",
  252. "debug_toolbar.panels.templates.TemplatesPanel",
  253. "debug_toolbar.panels.cache.CachePanel",
  254. "debug_toolbar.panels.signals.SignalsPanel",
  255. "debug_toolbar.panels.logging.LoggingPanel",
  256. ]
  257. # Django Rest Framework
  258. # http://www.django-rest-framework.org/api-guide/settings/
  259. REST_FRAMEWORK = {
  260. "DEFAULT_PERMISSION_CLASSES": [
  261. "misago.core.rest_permissions.IsAuthenticatedOrReadOnly"
  262. ],
  263. "DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer"],
  264. "EXCEPTION_HANDLER": "misago.core.exceptionhandler.handle_api_exception",
  265. "UNAUTHENTICATED_USER": "misago.users.models.AnonymousUser",
  266. "URL_FORMAT_OVERRIDE": None,
  267. }
  268. # Celery - Distributed Task Queue
  269. # http://docs.celeryproject.org/en/latest/userguide/configuration.html
  270. # Configure Celery to use Redis as message broker.
  271. CELERY_BROKER_URL = "redis://redis:6379/0"
  272. # Celery workers may leak the memory, eventually depriving the instance of resources.
  273. # This setting forces celery to stop worker, clean after it and create new one
  274. # after worker has processed 10 tasks.
  275. CELERY_WORKER_MAX_TASKS_PER_CHILD = 10
  276. # Misago specific settings
  277. # https://misago.readthedocs.io/en/latest/developers/settings.html
  278. # On dev instance, generate only three sizes of avatars instead of default 6 sizes.
  279. MISAGO_AVATARS_SIZES = [400, 200, 100]
  280. # PostgreSQL text search configuration to use in searches
  281. # Defaults to "simple", for list of installed configurations run "\dF" in "psql".
  282. # Standard configs as of PostgreSQL 9.5 are: dutch, english, finnish, french,
  283. # german, hungarian, italian, norwegian, portuguese, romanian, russian, simple,
  284. # spanish, swedish and turkish
  285. # Example on adding custom language can be found here: https://github.com/lemonskyjwt/plpstgrssearch
  286. MISAGO_SEARCH_CONFIG = "simple"
  287. # Path to the directory that Misago should use to prepare user data downloads.
  288. # Should not be accessible from internet.
  289. MISAGO_USER_DATA_DOWNLOADS_WORKING_DIR = os.path.join(BASE_DIR, "userdata")
  290. # Path to directory containing avatar galleries
  291. # Those galleries can be loaded by running loadavatargallery command
  292. MISAGO_AVATAR_GALLERY = os.path.join(BASE_DIR, "avatargallery")
  293. # Profile fields
  294. MISAGO_PROFILE_FIELDS = [
  295. {
  296. "name": _("Personal"),
  297. "fields": [
  298. "misago.users.profilefields.default.RealNameField",
  299. "misago.users.profilefields.default.GenderField",
  300. "misago.users.profilefields.default.BioField",
  301. "misago.users.profilefields.default.LocationField",
  302. ],
  303. },
  304. {
  305. "name": _("Contact"),
  306. "fields": [
  307. "misago.users.profilefields.default.TwitterHandleField",
  308. "misago.users.profilefields.default.SkypeIdField",
  309. "misago.users.profilefields.default.WebsiteField",
  310. ],
  311. },
  312. {
  313. "name": _("IP address"),
  314. "fields": ["misago.users.profilefields.default.JoinIpField"],
  315. },
  316. ]
  317. # Set dev instance to send e-mails to console
  318. EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
  319. # Display debug toolbar if IN_MISAGO_DOCKER enviroment var is set to "1"
  320. DEBUG_TOOLBAR_CONFIG = {
  321. "SHOW_TOOLBAR_CALLBACK": "misago.conf.debugtoolbar.enable_debug_toolbar"
  322. }