From 26fa63749df8cd185207c1d5ecd3720375fe6582 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 16 Feb 2021 02:50:05 -0500 Subject: [PATCH] add debug toolbar --- archivebox/core/settings.py | 15 +++++++-- archivebox/core/urls.py | 61 +++++++++++++++++++++---------------- setup.py | 1 + 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/archivebox/core/settings.py b/archivebox/core/settings.py index 1e2be75f..e0764585 100644 --- a/archivebox/core/settings.py +++ b/archivebox/core/settings.py @@ -40,7 +40,8 @@ LOGOUT_REDIRECT_URL = '/' PASSWORD_RESET_URL = '/accounts/password_reset/' APPEND_SLASH = True -DEBUG = DEBUG or ('--debug' in sys.argv) +DEBUG = True # DEBUG or ('--debug' in sys.argv) +DEBUG_TOOLBAR = True INSTALLED_APPS = [ 'django.contrib.auth', @@ -54,6 +55,12 @@ INSTALLED_APPS = [ 'django_extensions', ] +if DEBUG_TOOLBAR: + INSTALLED_APPS = [*INSTALLED_APPS, 'debug_toolbar'] + INTERNAL_IPS = ['0.0.0.0', '127.0.0.1', '*'] + DEBUG_TOOLBAR_CONFIG = { + "SHOW_TOOLBAR_CALLBACK": lambda request: True, + } MIDDLEWARE = [ @@ -64,6 +71,8 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ] +if DEBUG_TOOLBAR: + MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware', *MIDDLEWARE] AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', @@ -226,12 +235,12 @@ LOGGING = { 'loggers': { 'django': { 'handlers': ['console', 'logfile'], - 'level': 'DEBUG', + 'level': 'INFO', 'filters': ['noisyrequestsfilter'], }, 'django.server': { 'handlers': ['console', 'logfile'], - 'level': 'DEBUG', + 'level': 'INFO', 'filters': ['noisyrequestsfilter'], } }, diff --git a/archivebox/core/urls.py b/archivebox/core/urls.py index 182e4dca..fa2a1603 100644 --- a/archivebox/core/urls.py +++ b/archivebox/core/urls.py @@ -36,34 +36,41 @@ urlpatterns = [ path('', HomepageView.as_view(), name='Home'), ] - # # Proposed UI URLs spec - # path('', HomepageView) - # path('/add', AddView) - # path('/public', PublicIndexView) - # path('/snapshot/:slug', SnapshotView) - - # path('/admin', admin.site.urls) - # path('/accounts', django.contrib.auth.urls) +if settings.DEBUG_TOOLBAR: + import debug_toolbar + urlpatterns += [ + path('__debug__/', include(debug_toolbar.urls)), + ] - # # Prposed REST API spec - # # :slugs can be uuid, short_uuid, or any of the unique index_fields - # path('api/v1/'), - # path('api/v1/core/' [GET]) - # path('api/v1/core/snapshot/', [GET, POST, PUT]), - # path('api/v1/core/snapshot/:slug', [GET, PATCH, DELETE]), - # path('api/v1/core/archiveresult', [GET, POST, PUT]), - # path('api/v1/core/archiveresult/:slug', [GET, PATCH, DELETE]), - # path('api/v1/core/tag/', [GET, POST, PUT]), - # path('api/v1/core/tag/:slug', [GET, PATCH, DELETE]), - # path('api/v1/cli/', [GET]) - # path('api/v1/cli/{add,list,config,...}', [POST]), # pass query as kwargs directly to `run_subcommand` and return stdout, stderr, exitcode +# # Proposed FUTURE URLs spec +# path('', HomepageView) +# path('/add', AddView) +# path('/public', PublicIndexView) +# path('/snapshot/:slug', SnapshotView) - # path('api/v1/extractors/', [GET]) - # path('api/v1/extractors/:extractor/', [GET]), - # path('api/v1/extractors/:extractor/:func', [GET, POST]), # pass query as args directly to chosen function +# path('/admin', admin.site.urls) +# path('/accounts', django.contrib.auth.urls) - # future, just an idea: - # path('api/v1/scheduler/', [GET]) - # path('api/v1/scheduler/task/', [GET, POST, PUT]), - # path('api/v1/scheduler/task/:slug', [GET, PATCH, DELETE]), +# # Prposed REST API spec +# # :slugs can be uuid, short_uuid, or any of the unique index_fields +# path('api/v1/'), +# path('api/v1/core/' [GET]) +# path('api/v1/core/snapshot/', [GET, POST, PUT]), +# path('api/v1/core/snapshot/:slug', [GET, PATCH, DELETE]), +# path('api/v1/core/archiveresult', [GET, POST, PUT]), +# path('api/v1/core/archiveresult/:slug', [GET, PATCH, DELETE]), +# path('api/v1/core/tag/', [GET, POST, PUT]), +# path('api/v1/core/tag/:slug', [GET, PATCH, DELETE]), + +# path('api/v1/cli/', [GET]) +# path('api/v1/cli/{add,list,config,...}', [POST]), # pass query as kwargs directly to `run_subcommand` and return stdout, stderr, exitcode + +# path('api/v1/extractors/', [GET]) +# path('api/v1/extractors/:extractor/', [GET]), +# path('api/v1/extractors/:extractor/:func', [GET, POST]), # pass query as args directly to chosen function + +# future, just an idea: +# path('api/v1/scheduler/', [GET]) +# path('api/v1/scheduler/task/', [GET, POST, PUT]), +# path('api/v1/scheduler/task/:slug', [GET, PATCH, DELETE]), diff --git a/setup.py b/setup.py index 3ab4f238..0b0615e1 100755 --- a/setup.py +++ b/setup.py @@ -65,6 +65,7 @@ EXTRAS_REQUIRE = { "pytest", "bottle", "stdeb", + "django-debug-toolbar", ], }