1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-14 10:50:00 +00:00

[base] Extend django.debug context processor

This commit is contained in:
zhengxie 2017-10-14 16:47:13 +08:00
parent c0d533e250
commit 49f8917046
2 changed files with 16 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import re
import os
from django.conf import settings as dj_settings
from django.utils.functional import lazy
from constance import config
from seahub.settings import SEAFILE_VERSION, SITE_TITLE, SITE_NAME, \
@ -119,3 +120,17 @@ def base(request):
result['is_default_admin'] = request.user.admin_role == DEFAULT_ADMIN
return result
def debug(request):
"""
Returns context variables helpful for debugging.
"""
context_extras = {}
if dj_settings.DEBUG and request.META.get('REMOTE_ADDR') in dj_settings.INTERNAL_IPS or \
dj_settings.DEBUG and request.GET.get('_dev', '') == '1':
context_extras['debug'] = True
from django.db import connection
# Return a lazy reference that computes connection.queries on access,
# to ensure it contains queries triggered after this function runs.
context_extras['sql_queries'] = lazy(lambda: connection.queries, list)
return context_extras

View File

@ -184,7 +184,7 @@ LOCALE_PATHS = (
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'seahub.base.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',