author | Nishanth Amuluru <nishanth@fossee.in> |
Fri, 07 Jan 2011 12:58:39 +0530 | |
changeset 46 | 72db9563fae1 |
parent 10 | 3c7bffdeedbf |
child 50 | 869a9ab7e2df |
permissions | -rw-r--r-- |
46
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
1 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
2 |
def get_notification(nid, user): |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
3 |
""" if notification exists, and belongs to the current user, return it. |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
4 |
else return None. |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
5 |
""" |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
6 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
7 |
user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date') |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
8 |
current_notifications = user_notifications.filter(uniq_key=nid) |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
9 |
if user_notifications: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
10 |
current_notification = current_notifications[0] |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
11 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
12 |
try: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
13 |
newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False) |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
14 |
newest_notification = user_notifications.reverse()[0] |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
15 |
if newest_notification == newer_notification: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
16 |
newest_notification = None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
17 |
except Notification.DoesNotExist: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
18 |
newest_notification, newer_notification = None, None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
19 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
20 |
try: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
21 |
older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False) |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
22 |
oldest_notification = user_notifications[0] |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
23 |
if oldest_notification == older_notification: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
24 |
oldest_notification = None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
25 |
except: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
26 |
oldest_notification, older_notification = None, None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
27 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
28 |
return newest_notification, newer_notification, current_notification, older_notification, oldest_notification |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
29 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
30 |
else: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
31 |
return None, None, None, None, None |