Skip to content

Commit

Permalink
decorate views
Browse files Browse the repository at this point in the history
  • Loading branch information
dulmandakh committed Sep 17, 2024
1 parent 6563ed6 commit 63b04b5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions debug_toolbar/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
from django.contrib.auth.decorators import login_not_required
except ImportError:
def login_not_required(func):
return func
9 changes: 0 additions & 9 deletions debug_toolbar/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@

from debug_toolbar import settings as dt_settings

try:
from django.contrib.auth.decorators import login_not_required
except ImportError:

def login_not_required(func):
return func


def require_show_toolbar(view):
@functools.wraps(view)
@login_not_required
def inner(request, *args, **kwargs):
from debug_toolbar.middleware import get_show_toolbar

Expand Down
5 changes: 3 additions & 2 deletions debug_toolbar/panels/history/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.http import HttpResponseBadRequest, JsonResponse
from django.template.loader import render_to_string

from debug_toolbar._compat import login_not_required
from debug_toolbar.decorators import render_with_toolbar_language, require_show_toolbar
from debug_toolbar.panels.history.forms import HistoryStoreForm
from debug_toolbar.toolbar import DebugToolbar


@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def history_sidebar(request):
Expand Down Expand Up @@ -36,7 +37,7 @@ def history_sidebar(request):
return JsonResponse(context)
return HttpResponseBadRequest("Form errors")


@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def history_refresh(request):
Expand Down
4 changes: 4 additions & 0 deletions debug_toolbar/panels/sql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.template.loader import render_to_string
from django.views.decorators.csrf import csrf_exempt

from debug_toolbar._compat import login_not_required
from debug_toolbar.decorators import render_with_toolbar_language, require_show_toolbar
from debug_toolbar.forms import SignedDataForm
from debug_toolbar.panels.sql.forms import SQLSelectForm
Expand All @@ -17,6 +18,7 @@ def get_signed_data(request):


@csrf_exempt
@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def sql_select(request):
Expand Down Expand Up @@ -47,6 +49,7 @@ def sql_select(request):


@csrf_exempt
@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def sql_explain(request):
Expand Down Expand Up @@ -86,6 +89,7 @@ def sql_explain(request):


@csrf_exempt
@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def sql_profile(request):
Expand Down
2 changes: 2 additions & 0 deletions debug_toolbar/panels/templates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from django.template.loader import render_to_string
from django.utils.html import format_html, mark_safe

from debug_toolbar._compat import login_not_required
from debug_toolbar.decorators import render_with_toolbar_language, require_show_toolbar


@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def template_source(request):
Expand Down
2 changes: 2 additions & 0 deletions debug_toolbar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from django.utils.html import escape
from django.utils.translation import gettext as _

from debug_toolbar._compat import login_not_required
from debug_toolbar.decorators import render_with_toolbar_language, require_show_toolbar
from debug_toolbar.toolbar import DebugToolbar


@login_not_required
@require_show_toolbar
@render_with_toolbar_language
def render_panel(request):
Expand Down

0 comments on commit 63b04b5

Please sign in to comment.