in django_airavata/context_processors.py [0:0]
def get_notifications(request):
if request.user.is_authenticated and hasattr(request, 'airavata_client'):
unread_notifications = 0
try:
notifications = request.airavata_client.getAllNotifications(
request.authz_token, settings.GATEWAY_ID)
except Exception:
logger.warning("Failed to load notifications")
notifications = []
current_time = datetime.datetime.utcnow()
valid_notifications = []
for notification in notifications:
notification_data = notification.__dict__
expirationTime = datetime.datetime.fromtimestamp(
notification.expirationTime / 1000)
publishedTime = datetime.datetime.fromtimestamp(
notification.publishedTime / 1000)
if(expirationTime > current_time and publishedTime < current_time):
notification_data['url'] = request.build_absolute_uri(
reverse('django_airavata_api:ack-notifications'))\
+ "?id=" + str(notification.notificationId)
try:
notification_status = User_Notifications.objects.get(
notification_id=notification.notificationId,
username=request.user.username)
except ObjectDoesNotExist:
notification_status = User_Notifications.objects.create(
username=request.user.username,
notification_id=notification.notificationId)
notification_data['is_read'] = notification_status.is_read
if not notification_status.is_read:
unread_notifications += 1
valid_notifications.append(notification_data)
return {
"notifications": json.dumps(valid_notifications),
"unread_notifications": unread_notifications
}
else:
return {"notifications": json.dumps([])}