From 8ac037cbbbafa50cf4448b77b103f7dfee2de9c8 Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 11 Jun 2024 22:57:12 +0530 Subject: [PATCH] [UPDT] BASE: Updated login required function to pass notification error --- horilla/decorators.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/horilla/decorators.py b/horilla/decorators.py index 0a7b2d91e..eaad10b88 100755 --- a/horilla/decorators.py +++ b/horilla/decorators.py @@ -171,6 +171,9 @@ def manager_can_enter(function, perm): return _function +from urllib.parse import urlparse + + def login_required(view_func): def wrapped_view(request, *args, **kwargs): path = request.path @@ -190,7 +193,17 @@ def login_required(view_func): try: func = view_func(request, *args, **kwargs) except Exception as e: - logger.exception(e) + logger.error(e) + if ( + "notifications_notification" in str(e) + and request.headers.get("X-Requested-With") != "XMLHttpRequest" + ): + referer = request.META.get("HTTP_REFERER", "/") + messages.warning(request, str(e)) + return HttpResponse( + f"" + ) + if not settings.DEBUG: return render(request, "went_wrong.html") return view_func(request, *args, **kwargs)