diff --git a/hypha/apply/activity/context_processors.py b/hypha/apply/activity/context_processors.py index 6f94d6b9346ae288ed61d56abe7ee857f7c0195a..0a9a62168a8a8a6c96be2c8c54a01a98cf63d085 100644 --- a/hypha/apply/activity/context_processors.py +++ b/hypha/apply/activity/context_processors.py @@ -3,6 +3,7 @@ from .models import Activity def notification_context(request): context_data = dict() - if request.user.is_authenticated and request.user.is_apply_staff: - context_data['latest_notifications'] = Activity.objects.all().order_by('-timestamp')[:5] + if hasattr(request, 'user'): + if request.user.is_authenticated and request.user.is_apply_staff: + context_data['latest_notifications'] = Activity.objects.all().order_by('-timestamp')[:5] return context_data diff --git a/hypha/static_src/src/javascript/apply/notifications.js b/hypha/static_src/src/javascript/apply/notifications.js index 43e3de5143a943e3b449b3b212bf57384bf7d9c2..f3e619abdca50ae927468c0848652fcf564eaebe 100644 --- a/hypha/static_src/src/javascript/apply/notifications.js +++ b/hypha/static_src/src/javascript/apply/notifications.js @@ -1,17 +1,19 @@ function notificationToggle() { - document.getElementById("notificationDropdown").classList.toggle("show"); + 'use strict'; + document.getElementById('notificationDropdown').classList.toggle('show'); } // Close the dropdown menu if the user clicks outside of it -window.onclick = function(event) { - if (!event.target.matches('.dropbtn, .dropbtn *')) { - var dropdowns = document.getElementsByClassName("dropdown-content"); - var i; - for (i = 0; i < dropdowns.length; i++) { - var openDropdown = dropdowns[i]; - if (openDropdown.classList.contains('show')) { - openDropdown.classList.remove('show'); - } +window.onclick = function (event) { + 'use strict'; + if (!event.target.matches('.dropbtn, .dropbtn *')) { + var dropdowns = document.getElementsByClassName('dropdown-content'); + var i; + for (i = 0; i < dropdowns.length; i++) { + var openDropdown = dropdowns[i]; + if (openDropdown.classList.contains('show')) { + notificationToggle(); + } + } } - } -} +};