diff --git a/InvenTree/InvenTree/middleware.py b/InvenTree/InvenTree/middleware.py index 26cbc95bbf..37b9a27c63 100644 --- a/InvenTree/InvenTree/middleware.py +++ b/InvenTree/InvenTree/middleware.py @@ -91,6 +91,8 @@ class QueryCountMiddleware(object): To enable this middleware, set 'log_queries: True' in the local InvenTree config file. Reference: https://www.dabapps.com/blog/logging-sql-queries-django-13/ + + Note: 2020-08-15 - This is no longer used, instead we now rely on the django-debug-toolbar addon """ def __init__(self, get_response): diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index e5b14314b5..fb68f65497 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -172,11 +172,15 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'InvenTree.middleware.AuthRequiredMiddleware', + + 'InvenTree.middleware.AuthRequiredMiddleware' ] -if CONFIG.get('log_queries', False): - MIDDLEWARE.append('InvenTree.middleware.QueryCountMiddleware') +# If the debug toolbar is enabled, add the modules +if DEBUG and CONFIG.get('debug_toolbar', False): + print("Running with DEBUG_TOOLBAR enabled") + INSTALLED_APPS.append('debug_toolbar') + MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware') ROOT_URLCONF = 'InvenTree.urls' @@ -377,3 +381,8 @@ DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage' DBBACKUP_STORAGE_OPTIONS = { 'location': CONFIG.get('backup_dir', tempfile.gettempdir()), } + +# Internal IP addresses allowed to see the debug toolbar +INTERNAL_IPS = [ + '127.0.0.1', +] diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index c2d0d0f48f..d0076714ae 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -6,6 +6,7 @@ Passes URL lookup downstream to each app as required. from django.conf.urls import url, include +from django.urls import path from django.contrib import admin from django.contrib.auth import views as auth_views from qr_code import urls as qr_code_urls @@ -135,5 +136,12 @@ urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # Media file access urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +# Debug toolbar access (if in DEBUG mode) +if settings.DEBUG and 'debug_toolbar' in settings.INSTALLED_APPS: + import debug_toolbar + urlpatterns = [ + path('__debug/', include(debug_toolbar.urls)), + ] + urlpatterns + # Send any unknown URLs to the parts page urlpatterns += [url(r'^.*$', RedirectView.as_view(url='/index/', permanent=False), name='index')] diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 5447606337..1c776a6f7a 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -58,9 +58,10 @@ static_root: '../inventree_static' # - git # - ssh -# Logging options -# If debug mode is enabled, set log_queries to True to show aggregate database queries in the debug console -log_queries: False +# Set debug_toolbar to True to enable a debugging toolbar for InvenTree +# Note: This will only be displayed if DEBUG mode is enabled, +# and only if InvenTree is accessed from a local IP (127.0.0.1) +debug_toolbar: False # Backup options # Set the backup_dir parameter to store backup files in a specific location diff --git a/requirements.txt b/requirements.txt index f09cc35167..c668612914 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,4 +21,5 @@ python-coveralls==2.9.1 # Coveralls linking (for Travis) rapidfuzz==0.7.6 # Fuzzy string matching django-stdimage==5.1.1 # Advanced ImageField management django-tex==1.1.7 # LaTeX PDF export -django-weasyprint==1.0.1 # HTML PDF export \ No newline at end of file +django-weasyprint==1.0.1 # HTML PDF export +django-debug-toolbar==2.2 # Debug / profiling toolbar \ No newline at end of file