summaryrefslogtreecommitdiff
path: root/profile/utils.py
diff options
context:
space:
mode:
authorNishanth Amuluru2011-01-07 12:58:39 +0530
committerNishanth Amuluru2011-01-07 12:58:39 +0530
commit8f97d1f4e4c1adbd69678a63e40b0b55a6037c73 (patch)
treef3e6aabd465dfb09dacf3e0f168b532887764f97 /profile/utils.py
parent72f39fb5e9b1d548f4b5a5e46a633df36c6c459a (diff)
downloadpytask-8f97d1f4e4c1adbd69678a63e40b0b55a6037c73.tar.gz
pytask-8f97d1f4e4c1adbd69678a63e40b0b55a6037c73.tar.bz2
pytask-8f97d1f4e4c1adbd69678a63e40b0b55a6037c73.zip
created a function for viewign notifications
Diffstat (limited to 'profile/utils.py')
-rw-r--r--profile/utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/profile/utils.py b/profile/utils.py
index e69de29..00cfaec 100644
--- a/profile/utils.py
+++ b/profile/utils.py
@@ -0,0 +1,31 @@
+
+def get_notification(nid, user):
+ """ if notification exists, and belongs to the current user, return it.
+ else return None.
+ """
+
+ user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date')
+ current_notifications = user_notifications.filter(uniq_key=nid)
+ if user_notifications:
+ current_notification = current_notifications[0]
+
+ try:
+ newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False)
+ newest_notification = user_notifications.reverse()[0]
+ if newest_notification == newer_notification:
+ newest_notification = None
+ except Notification.DoesNotExist:
+ newest_notification, newer_notification = None, None
+
+ try:
+ older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False)
+ oldest_notification = user_notifications[0]
+ if oldest_notification == older_notification:
+ oldest_notification = None
+ except:
+ oldest_notification, older_notification = None, None
+
+ return newest_notification, newer_notification, current_notification, older_notification, oldest_notification
+
+ else:
+ return None, None, None, None, None