author | nishanth |
Sun, 28 Feb 2010 22:49:05 +0530 | |
changeset 153 | 925af1b4ee65 |
parent 150 | 604808d27483 |
child 156 | 7cad1e92713d |
permissions | -rw-r--r-- |
123 | 1 |
from datetime import datetime |
2 |
from django.contrib.auth.models import User |
|
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
3 |
from pytask.taskapp.models import Notification, RIGHTS_CHOICES |
57 | 4 |
|
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
5 |
def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None): |
57 | 6 |
""" |
7 |
creates a notification based on the passed arguments. |
|
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
8 |
role: role of the notification - look at choices in models |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
9 |
sent_to: a user to which the notification is to be sent |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
10 |
sent_from : a user from which the message has originated |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
11 |
A user who approves/rejects in case of request |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
12 |
A mentor who closes/complets the task |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
13 |
reply: A boolean |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
14 |
task: a task if applicable |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
15 |
requested_by: a user makes the request |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
16 |
A mentor who assigns credits in case of pynts |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
17 |
A mentor who requests to act as a mentor |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
18 |
remarks: any remarks for rejecting |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
19 |
receiving_user: user receiving pynts |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
20 |
pynts: the obvious |
57 | 21 |
""" |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
22 |
|
57 | 23 |
notification = Notification(sent_date = datetime.now()) |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
24 |
notification.role = role |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
25 |
notification.sent_to = sent_to |
57 | 26 |
notification.save() |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
27 |
|
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
28 |
if role == "PY": |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
29 |
|
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
30 |
notification.sent_from = sent_from |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
31 |
notification.task = task |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
32 |
notification.pynts = pynts |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
33 |
|
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
34 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
35 |
credits_url = '<a href="/task/assigncredits/tid=%s">%s</a>'%(task.id, "click here") |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
36 |
mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
37 |
admin_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
38 |
user_url = '<a href="/user/view/uid=%s">%s</a>'%(receiving_user.id, receiving_user.username) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
39 |
|
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
40 |
if reply: |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
41 |
notification.sub = "Approved request for assign of credits for %s"%task.title[:20] |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
42 |
notification.message = """ Request made by %s to assign %s pynts to %s for the task %s has been approved by %s<br /> |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
43 |
%s if you want the view/assign pynts page of the task.<br />"""%(mentor_url, pynts, user_url, task_url, admin_url, credits_url) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
44 |
|
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
45 |
else: |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
46 |
notification.sub = "Rejected request for assign of credits for %s"%task.title[:20] |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
47 |
notification.message = """ Request made by %s to assign %s pynts to %s for the task %s has been rejected by %s.<br /> """%(mentor_url, pynts, user_url, task_url, admin_url) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
48 |
if remarks: |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
49 |
notification.remarks = remarks |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
50 |
notification.message += "Reason: %s<br />"%remarks |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
51 |
notification.message += "<br />" |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
52 |
|
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
53 |
elif role == "MT": |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
54 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
55 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
56 |
requested_mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
57 |
new_mentor = sent_from |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
58 |
new_mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(new_mentor.id, new_mentor.username) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
59 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
60 |
if reply: |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
61 |
notification.sub = "New mentor for the task %s"%task.title[:20] |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
62 |
notification.message = "%s has accepted the request made by %s, asking him act as a mentor for the task %s<br />"%(new_mentor_url, requested_mentor_url, task_url) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
63 |
notification.message += "He can be contacted on %s"%new_mentor.email |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
64 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
65 |
else: |
144
581ad20b8c39
modified get_user method to give only count of unread requests.
nishanth
parents:
142
diff
changeset
|
66 |
notification.sub = "%s rejected request to act as a mentor"%new_mentor.username |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
67 |
notification.message = "%s has rejected your request asking him to act as a mentor for %s.<br />"%(new_mentor_url, task_url) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
68 |
if remarks: |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
69 |
notification.message += "Remarks: %s<br />"%remarks |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
70 |
|
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
71 |
elif role in ["DV", "MG", "AD"]: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
72 |
|
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
73 |
accepting_user = sent_from |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
133
diff
changeset
|
74 |
user_url = '<a href="/user/view/uid=%s">%s</a>'%(accepting_user.id, accepting_user.username) ## i mean the user who has accepted it |
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
133
diff
changeset
|
75 |
requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
76 |
role_rights = dict(RIGHTS_CHOICES)[role] |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
77 |
role_learn_url = "/about/%s"%role_rights.lower() |
142 | 78 |
a_or_an = "an" if role_rights == "AD" else "a" |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
79 |
|
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
80 |
if reply: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
81 |
notification.sub = "New %s for the site"%role_rights |
142 | 82 |
notification.message = "%s has accepted request made by %s asking him to act as %s %s for the website.<br />"%(user_url, requested_by_url, a_or_an, role_rights) |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
83 |
else: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
84 |
notification.sub = "Rejected your request to act as %s"%role_rights |
147 | 85 |
notification.message = "%s has rejected your request asking him to act as %s %s.<br />"%(user_url, a_or_an, role_rights) |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
86 |
if remarks: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
87 |
notification.message += "Remarks: %s<br />"%remarks |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
88 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
89 |
elif role == "NT": |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
90 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
91 |
new_mentor = sent_to |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
92 |
mentor_learn_url = '<sup><a href="/about/mentor">learn more</a></sup>' |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
93 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
94 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
95 |
notification.sub = "You are mentoring the task %s"%task.title[:20] |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
96 |
notification.message = "You have accepted to act as a mentor%s for the task %s.<br />"%(mentor_learn_url, task_url) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
97 |
notification.message += " Here is a list of other mentors and their email addresses.<br /> <ul>" |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
98 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
99 |
for a_mentor in task.mentors.exclude(id=new_mentor.id): |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
100 |
notification.message += "<li> %s - %s </li>"%(a_mentor.username, a_mentor.email) |
150
604808d27483
fixed a small bug in create_notification for the case NT.
nishanth
parents:
147
diff
changeset
|
101 |
notification.message += "</ul>" |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
102 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
103 |
working_users = task.assigned_users.all() |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
104 |
if working_users: |
153 | 105 |
notification.message += "List of users working on the task.<br />" |
106 |
notification.message += "<ul>" |
|
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
107 |
for a_user in working_users: |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
108 |
notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email) |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
109 |
notification.message += "</ul><br />" |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
110 |
notification.message += "Happy Mentoring." |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
111 |
|
153 | 112 |
elif role in ["CM", "CD"]: |
113 |
mentor = sent_from |
|
114 |
mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username) |
|
115 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
|
116 |
||
117 |
if role == "CM": |
|
118 |
notification.sub = "%s has been marked complete"%task.title |
|
119 |
notification.message = "The task %s has been marked complete by %s.<br />"%(task_url, mentor_url) |
|
120 |
||
121 |
elif role == "CD": |
|
122 |
notification.sub = "%s has been closed"%task.title |
|
123 |
notification.message = "The task %s has been closed by %s.<br />"%(task_url, mentor_url) |
|
124 |
||
125 |
if remarks: |
|
126 |
notification.message += "<b>Remarks:</b> %s"%remarks |
|
127 |
||
128 |
||
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
129 |
notification.save() |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
130 |
|
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
131 |
def mark_notification_read(notification_id): |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
132 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
133 |
makes a notification identified by the notification_id read. |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
134 |
arguments: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
135 |
notification_id - a number denoting the id of the Notification object |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
136 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
137 |
try: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
138 |
notification = Notification.objects.get(id = notification_id) |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
139 |
except Notification.DoesNotExist: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
140 |
return False |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
141 |
notification.is_read = True |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
142 |
notification.save() |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
143 |
return True |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
144 |
|
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
145 |
def delete_notification(notification_id): |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
146 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
147 |
deletes a notification identified by the notification_id. |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
148 |
arguments: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
149 |
notification_id - a number denoting the id of the Notification object |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
150 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
151 |
try: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
152 |
notification = Notification.objects.get(id = notification_id) |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
153 |
except Notification.DoesNotExist: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
154 |
return False |
123 | 155 |
notification.is_deleted = True |
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
156 |
notification.save() |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
157 |
return True |
123 | 158 |
|
159 |
def get_notification(nid, user): |
|
160 |
""" if notification exists, and belongs to the current user, return it. |
|
161 |
else return None. |
|
162 |
""" |
|
163 |
||
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
164 |
user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date') |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
165 |
current_notifications = user_notifications.filter(id=nid) |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
166 |
if user_notifications: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
167 |
current_notification = current_notifications[0] |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
168 |
|
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
169 |
try: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
170 |
newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False) |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
171 |
newest_notification = user_notifications.reverse()[0] |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
172 |
if newest_notification == newer_notification: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
173 |
newest_notification = None |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
174 |
except Notification.DoesNotExist: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
175 |
newest_notification, newer_notification = None, None |
123 | 176 |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
177 |
try: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
178 |
older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False) |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
179 |
oldest_notification = user_notifications[0] |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
180 |
if oldest_notification == older_notification: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
181 |
oldest_notification = None |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
182 |
except: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
183 |
oldest_notification, older_notification = None, None |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
184 |
|
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
185 |
return newest_notification, newer_notification, current_notification, older_notification, oldest_notification |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
186 |
|
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
187 |
else: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
188 |
return None, None, None, None, None |