Skip to content

Commit

Permalink
Unify binded context processors
Browse files Browse the repository at this point in the history
Adds additional exception catching as well reducing unnecessary imports on each request
  • Loading branch information
Maffooch authored Jan 12, 2024
1 parent 4bbc70f commit 64032c6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dojo/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# import the settings file
from django.conf import settings

from dojo.models import Alerts, UserAnnouncement, System_Settings

def globalize_vars(request):
# return the value you want as a dictionnary. you may add multiple values in there.
Expand Down Expand Up @@ -28,24 +28,24 @@ def globalize_vars(request):


def bind_system_settings(request):
from dojo.models import System_Settings
return {'system_settings': System_Settings.objects.get()}


def bind_alert_count(request):
if not settings.DISABLE_ALERT_COUNTER:
from dojo.models import Alerts
if request.user.is_authenticated:
try:
if not settings.DISABLE_ALERT_COUNTER and request.user.is_authenticated:
return {'alert_count': Alerts.objects.filter(user_id=request.user).count()}
return {}
except Exception:
pass
finally:
return {}


def bind_announcement(request):
from dojo.models import UserAnnouncement
try:
if request.user.is_authenticated:
user_announcement = UserAnnouncement.objects.select_related('announcement').get(user=request.user)
return {'announcement': user_announcement.announcement}
return {}
return {'announcement': UserAnnouncement.objects.select_related('announcement').get(user=request.user)}
except Exception:
pass
finally:
return {}

0 comments on commit 64032c6

Please sign in to comment.