Skip to content

Commit

Permalink
Replace request.is_ajax calls with function
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Jan 28, 2025
1 parent 07a4a14 commit deb2bda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion python/nav/web/auth/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
authorization_not_required,
)
from nav.web.auth.sudo import get_sudoer
from nav.web.utils import is_ajax


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -107,7 +108,7 @@ def redirect_to_login(self, request):
response.
"""
if request.is_ajax():
if is_ajax(request):
return HttpResponse(status=401)

new_url = get_login_url(request)
Expand Down
8 changes: 4 additions & 4 deletions python/nav/web/syslogger/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from nav.models.logger import LogMessage
from nav.models.logger import ErrorError
from nav.web.syslogger.forms import LoggerGroupSearchForm
from nav.web.utils import create_title
from nav.web.utils import create_title, is_ajax


DATEFORMAT = "%Y-%m-%d %H:%M:%S"
Expand Down Expand Up @@ -204,7 +204,7 @@ def index(request):


def group_search(request):
if not request.is_ajax():
if not is_ajax(request):
return HttpResponseRedirect(reverse(index) + '?' + request.GET.urlencode())
return handle_search(request, LoggerGroupSearchForm, reverse(group_search))

Expand All @@ -213,7 +213,7 @@ def exceptions_response(request):
"""
Handler for exception-mode.
"""
if not request.is_ajax():
if not is_ajax(request):
return HttpResponseRedirect(reverse(index) + '?' + request.GET.urlencode())

account = get_account(request)
Expand All @@ -236,7 +236,7 @@ def errors_response(request):
"""
Handler for error-mode.
"""
if not request.is_ajax():
if not is_ajax(request):
return HttpResponseRedirect(reverse(index) + '?' + request.GET.urlencode())

account = get_account(request)
Expand Down
4 changes: 4 additions & 0 deletions python/nav/web/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import qrcode.image.pil


def is_ajax(request):
return request.headers.get("x-requested-with") == "XMLHttpRequest"


def get_navpath_root():
"""Returns the default navpath root
Expand Down

0 comments on commit deb2bda

Please sign in to comment.