Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.py 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. from __future__ import absolute_import, unicode_literals
  2. import warnings
  3. from django.conf import settings
  4. from django.utils import six
  5. from django.utils.lru_cache import lru_cache
  6. # Always import this module as follows:
  7. # from debug_toolbar import settings [as dt_settings]
  8. # Don't import directly CONFIG or PANELs, or you will miss changes performed
  9. # with override_settings in tests.
  10. CONFIG_DEFAULTS = {
  11. # Toolbar options
  12. 'DISABLE_PANELS': {'debug_toolbar.panels.redirects.RedirectsPanel'},
  13. 'INSERT_BEFORE': '</body>',
  14. 'RENDER_PANELS': None,
  15. 'RESULTS_CACHE_SIZE': 10,
  16. 'ROOT_TAG_EXTRA_ATTRS': '',
  17. 'SHOW_COLLAPSED': False,
  18. 'SHOW_TOOLBAR_CALLBACK': 'debug_toolbar.middleware.show_toolbar',
  19. # Panel options
  20. 'EXTRA_SIGNALS': [],
  21. 'ENABLE_STACKTRACES': True,
  22. 'HIDE_IN_STACKTRACES': (
  23. 'socketserver' if six.PY3 else 'SocketServer',
  24. 'threading',
  25. 'wsgiref',
  26. 'debug_toolbar',
  27. 'django.db',
  28. 'django.core.handlers',
  29. 'django.core.servers',
  30. 'django.utils.decorators',
  31. 'django.utils.deprecation',
  32. 'django.utils.functional',
  33. ),
  34. 'PROFILER_MAX_DEPTH': 10,
  35. 'SHOW_TEMPLATE_CONTEXT': True,
  36. 'SKIP_TEMPLATE_PREFIXES': (
  37. 'django/forms/widgets/',
  38. 'admin/widgets/',
  39. ),
  40. 'SQL_WARNING_THRESHOLD': 500, # milliseconds
  41. }
  42. @lru_cache()
  43. def get_config():
  44. USER_CONFIG = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {})
  45. # Backward-compatibility for 1.0, remove in 2.0.
  46. _RENAMED_CONFIG = {
  47. 'RESULTS_STORE_SIZE': 'RESULTS_CACHE_SIZE',
  48. 'ROOT_TAG_ATTRS': 'ROOT_TAG_EXTRA_ATTRS',
  49. 'HIDDEN_STACKTRACE_MODULES': 'HIDE_IN_STACKTRACES'
  50. }
  51. for old_name, new_name in _RENAMED_CONFIG.items():
  52. if old_name in USER_CONFIG:
  53. warnings.warn(
  54. "%r was renamed to %r. Update your DEBUG_TOOLBAR_CONFIG "
  55. "setting." % (old_name, new_name), DeprecationWarning)
  56. USER_CONFIG[new_name] = USER_CONFIG.pop(old_name)
  57. if 'HIDE_DJANGO_SQL' in USER_CONFIG:
  58. warnings.warn(
  59. "HIDE_DJANGO_SQL was removed. Update your "
  60. "DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning)
  61. USER_CONFIG.pop('HIDE_DJANGO_SQL')
  62. if 'TAG' in USER_CONFIG:
  63. warnings.warn(
  64. "TAG was replaced by INSERT_BEFORE. Update your "
  65. "DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning)
  66. USER_CONFIG['INSERT_BEFORE'] = '</%s>' % USER_CONFIG.pop('TAG')
  67. CONFIG = CONFIG_DEFAULTS.copy()
  68. CONFIG.update(USER_CONFIG)
  69. if 'INTERCEPT_REDIRECTS' in USER_CONFIG:
  70. warnings.warn(
  71. "INTERCEPT_REDIRECTS is deprecated. Please use the "
  72. "DISABLE_PANELS config in the "
  73. "DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning)
  74. if USER_CONFIG['INTERCEPT_REDIRECTS']:
  75. if 'debug_toolbar.panels.redirects.RedirectsPanel' \
  76. in CONFIG['DISABLE_PANELS']:
  77. # RedirectsPanel should be enabled
  78. try:
  79. CONFIG['DISABLE_PANELS'].remove(
  80. 'debug_toolbar.panels.redirects.RedirectsPanel'
  81. )
  82. except KeyError:
  83. # We wanted to remove it, but it didn't exist. This is fine
  84. pass
  85. elif 'debug_toolbar.panels.redirects.RedirectsPanel' \
  86. not in CONFIG['DISABLE_PANELS']:
  87. # RedirectsPanel should be disabled
  88. CONFIG['DISABLE_PANELS'].add(
  89. 'debug_toolbar.panels.redirects.RedirectsPanel'
  90. )
  91. return CONFIG
  92. PANELS_DEFAULTS = [
  93. 'debug_toolbar.panels.versions.VersionsPanel',
  94. 'debug_toolbar.panels.timer.TimerPanel',
  95. 'debug_toolbar.panels.settings.SettingsPanel',
  96. 'debug_toolbar.panels.headers.HeadersPanel',
  97. 'debug_toolbar.panels.request.RequestPanel',
  98. 'debug_toolbar.panels.sql.SQLPanel',
  99. 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
  100. 'debug_toolbar.panels.templates.TemplatesPanel',
  101. 'debug_toolbar.panels.cache.CachePanel',
  102. 'debug_toolbar.panels.signals.SignalsPanel',
  103. 'debug_toolbar.panels.logging.LoggingPanel',
  104. 'debug_toolbar.panels.redirects.RedirectsPanel',
  105. ]
  106. @lru_cache()
  107. def get_panels():
  108. try:
  109. PANELS = list(settings.DEBUG_TOOLBAR_PANELS)
  110. except AttributeError:
  111. PANELS = PANELS_DEFAULTS
  112. else:
  113. # Backward-compatibility for 1.0, remove in 2.0.
  114. _RENAMED_PANELS = {
  115. 'debug_toolbar.panels.version.VersionDebugPanel':
  116. 'debug_toolbar.panels.versions.VersionsPanel',
  117. 'debug_toolbar.panels.timer.TimerDebugPanel':
  118. 'debug_toolbar.panels.timer.TimerPanel',
  119. 'debug_toolbar.panels.settings_vars.SettingsDebugPanel':
  120. 'debug_toolbar.panels.settings.SettingsPanel',
  121. 'debug_toolbar.panels.headers.HeaderDebugPanel':
  122. 'debug_toolbar.panels.headers.HeadersPanel',
  123. 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel':
  124. 'debug_toolbar.panels.request.RequestPanel',
  125. 'debug_toolbar.panels.sql.SQLDebugPanel':
  126. 'debug_toolbar.panels.sql.SQLPanel',
  127. 'debug_toolbar.panels.template.TemplateDebugPanel':
  128. 'debug_toolbar.panels.templates.TemplatesPanel',
  129. 'debug_toolbar.panels.cache.CacheDebugPanel':
  130. 'debug_toolbar.panels.cache.CachePanel',
  131. 'debug_toolbar.panels.signals.SignalDebugPanel':
  132. 'debug_toolbar.panels.signals.SignalsPanel',
  133. 'debug_toolbar.panels.logger.LoggingDebugPanel':
  134. 'debug_toolbar.panels.logging.LoggingPanel',
  135. 'debug_toolbar.panels.redirects.InterceptRedirectsDebugPanel':
  136. 'debug_toolbar.panels.redirects.RedirectsPanel',
  137. 'debug_toolbar.panels.profiling.ProfilingDebugPanel':
  138. 'debug_toolbar.panels.profiling.ProfilingPanel',
  139. }
  140. for index, old_panel in enumerate(PANELS):
  141. new_panel = _RENAMED_PANELS.get(old_panel)
  142. if new_panel is not None:
  143. warnings.warn(
  144. "%r was renamed to %r. Update your DEBUG_TOOLBAR_PANELS "
  145. "setting." % (old_panel, new_panel), DeprecationWarning)
  146. PANELS[index] = new_panel
  147. return PANELS