author | Nishanth Amuluru <nishanth@fossee.in> |
Thu, 06 Jan 2011 12:08:36 +0530 | |
changeset 226 | b4a3ec34c061 |
parent 219 | f04a1ec7a07f |
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 |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
12 |
A reviewer who closes/complets the task |
131
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 |
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
16 |
A reviewer who assigns pynts in case of pynts |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
17 |
A reviewer who requests to act as a reviewer |
131
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) |
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
35 |
pynts_url = '<a href="/task/assignpynts/tid=%s">%s</a>'%(task.id, "click here") |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
36 |
reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) |
129
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: |
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
41 |
notification.sub = "Approved request for assign of pynts 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 /> |
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
43 |
%s if you want the view/assign pynts page of the task.<br />"""%(reviewer_url, pynts, user_url, task_url, admin_url, pynts_url) |
129
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: |
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
46 |
notification.sub = "Rejected request for assign of pynts for %s"%task.title[:20] |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
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 /> """%(reviewer_url, pynts, user_url, task_url, admin_url) |
129
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 |
|
156 | 55 |
notification.task = task |
56 |
notification.sent_from = sent_from |
|
57 |
||
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
58 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
59 |
requested_reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
60 |
new_reviewer = sent_from |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
61 |
new_reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(new_reviewer.id, new_reviewer.username) |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
62 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
63 |
if reply: |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
64 |
notification.sub = "New reviewer for the task %s"%task.title[:20] |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
65 |
notification.message = "%s has accepted the request made by %s, asking him act as a reviewer for the task %s<br />"%(new_reviewer_url, requested_reviewer_url, task_url) |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
66 |
notification.message += "He can be contacted on %s"%new_reviewer.email |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
67 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
68 |
else: |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
69 |
notification.sub = "%s rejected request to act as a reviewer"%new_reviewer.username |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
70 |
notification.message = "%s has rejected your request asking him to act as a reviewer for %s.<br />"%(new_reviewer_url, task_url) |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
71 |
if remarks: |
162 | 72 |
notification.remarks = remarks |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
73 |
notification.message += "Remarks: %s<br />"%remarks |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
74 |
|
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
75 |
elif role in ["DV", "MG", "AD"]: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
76 |
|
156 | 77 |
notification.sent_from = sent_from |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
78 |
accepting_user = sent_from |
141
2489392ffb56
added the functionality to request a user to be AD MG DV.
nishanth
parents:
133
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
role_rights = dict(RIGHTS_CHOICES)[role] |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
82 |
role_learn_url = "/about/%s"%role_rights.lower() |
142 | 83 |
a_or_an = "an" if role_rights == "AD" else "a" |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
84 |
|
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
85 |
if reply: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
86 |
notification.sub = "New %s for the site"%role_rights |
142 | 87 |
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
|
88 |
else: |
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
89 |
notification.sub = "Rejected your request to act as %s"%role_rights |
147 | 90 |
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
|
91 |
if remarks: |
162 | 92 |
notification.remarks = remarks |
132
ca88bf4ad362
implemented notification functionality for AD MG DV.
nishanth
parents:
131
diff
changeset
|
93 |
notification.message += "Remarks: %s<br />"%remarks |
131
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 |
elif role == "NT": |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
96 |
|
156 | 97 |
notification.task = task |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
98 |
new_reviewer = sent_to |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
99 |
reviewer_learn_url = '<sup><a href="/about/reviewer/">learn more</a></sup>' |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
100 |
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
|
101 |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
102 |
notification.sub = "You are reviewering the task %s"%task.title[:20] |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
103 |
notification.message = "You have accepted to act as a reviewer%s for the task %s.<br />"%(reviewer_learn_url, task_url) |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
104 |
notification.message += " Here is a list of other reviewers and their email addresses.<br /> <ul>" |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
105 |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
106 |
for a_reviewer in task.reviewers.exclude(id=new_reviewer.id): |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
107 |
notification.message += "<li> %s - %s </li>"%(a_reviewer.username, a_reviewer.email) |
150
604808d27483
fixed a small bug in create_notification for the case NT.
nishanth
parents:
147
diff
changeset
|
108 |
notification.message += "</ul>" |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
109 |
|
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
110 |
working_users = task.assigned_users.all() |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
111 |
if working_users: |
153 | 112 |
notification.message += "List of users working on the task.<br />" |
113 |
notification.message += "<ul>" |
|
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
114 |
for a_user in working_users: |
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
115 |
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
|
116 |
notification.message += "</ul><br />" |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
117 |
notification.message += "Happy Reviewering." |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
118 |
|
161 | 119 |
elif role == "NU": |
120 |
||
183
c088c79a225c
now there is also a notification sent to a new created user in seed_db.
nishanth
parents:
167
diff
changeset
|
121 |
start_here_url = '<a href="/about/starthere/" taget="_blank">click here</a>' |
161 | 122 |
notification.sub = "Welcome %s"%sent_to.username |
123 |
notification.message = "Welcome to PyTasks %s.<br />"%sent_to.username |
|
183
c088c79a225c
now there is also a notification sent to a new created user in seed_db.
nishanth
parents:
167
diff
changeset
|
124 |
notification.message += "%s to know more."%start_here_url |
161 | 125 |
|
126 |
elif role in ["ND", "NG", "NA"]: |
|
127 |
||
128 |
rights_dict = dict(RIGHTS_CHOICES) |
|
129 |
||
130 |
if role == "ND": |
|
131 |
role_rights = rights_dict["DV"] |
|
132 |
elif role == "NG": |
|
133 |
role_rights = rights_dict["MG"] |
|
134 |
elif role == "NA": |
|
135 |
role_rights = rights_dict["AD"] |
|
136 |
||
137 |
requested_by_url = r'<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) |
|
138 |
role_learn_url = r'<a href="/about/%s" target="_blank">click here</a>'%role_rights.lower() |
|
139 |
a_or_an = "an" if role_rights == "Admin" else "a" |
|
140 |
||
141 |
notification.sub = "You are now %s %s"%(a_or_an, role_rights) |
|
142 |
notification.message = r"You have accepted the request made by %s asking you to act as %s %s in the site "%(requested_by_url, a_or_an, role_rights) |
|
143 |
notification.message += "and you are now %s %s in the site.<br /> %s to learn more on %s."%(a_or_an, role_rights, role_learn_url, role_rights) |
|
144 |
||
145 |
||
153 | 146 |
elif role in ["CM", "CD"]: |
156 | 147 |
|
148 |
notification.sent_from = sent_from |
|
149 |
notification.role = role |
|
150 |
notification.task = task |
|
151 |
notification.remarks = remarks |
|
152 |
||
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
153 |
reviewer = sent_from |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
154 |
reviewer_url = '<a href="/user/view/uid=%s">%s</a>'%(reviewer.id, reviewer.username) |
153 | 155 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
156 |
||
157 |
if role == "CM": |
|
158 |
notification.sub = "%s has been marked complete"%task.title |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
159 |
notification.message = "The task %s has been marked complete by %s.<br />"%(task_url, reviewer_url) |
153 | 160 |
|
161 |
elif role == "CD": |
|
162 |
notification.sub = "%s has been closed"%task.title |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
163 |
notification.message = "The task %s has been closed by %s.<br />"%(task_url, reviewer_url) |
153 | 164 |
|
165 |
if remarks: |
|
162 | 166 |
notification.remarks = remarks |
153 | 167 |
notification.message += "<b>Remarks:</b> %s"%remarks |
168 |
||
162 | 169 |
elif role == "AU": |
170 |
||
171 |
notification.task = task |
|
167 | 172 |
notification.sent_from = sent_from |
162 | 173 |
added_user = sent_to |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
174 |
reviewer = sent_from |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
175 |
assigned_by_url = '<a href="/user/view/uid=%s">%s</a>'%(reviewer.id, reviewer.username) |
162 | 176 |
task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
177 |
||
178 |
notification.sub = "Your claim for the task %s accepted."%task.title[:20] |
|
179 |
notification.message = "You have been selected to work on the task %s by %s.<br />"%(task_url, assigned_by_url) |
|
219
f04a1ec7a07f
Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents:
218
diff
changeset
|
180 |
notification.message += "You can now start working on the task and will be pynted by the reviewers for your work.<br />" |
162 | 181 |
|
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
182 |
notification.message += " Here is a list of reviewers for the task and their email addresses.<br /> <ul>" |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
183 |
for a_reviewer in task.reviewers.all(): |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
184 |
notification.message += "<li> %s - %s </li>"%(a_reviewer.username, a_reviewer.email) |
162 | 185 |
notification.message += "</ul>" |
186 |
||
187 |
working_users = task.assigned_users.exclude(id=added_user.id) |
|
188 |
if working_users: |
|
189 |
notification.message += "List of other users working on the task.<br />" |
|
190 |
notification.message += "<ul>" |
|
191 |
for a_user in working_users: |
|
192 |
notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email) |
|
193 |
notification.message += "</ul><br />" |
|
194 |
||
195 |
elif role == "RU": |
|
196 |
||
197 |
notification.task = task |
|
167 | 198 |
notification.sent_from = sent_from |
162 | 199 |
removed_user = sent_to |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
200 |
reviewer = sent_from |
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
201 |
removed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(reviewer.id, reviewer.username) |
162 | 202 |
task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
203 |
claim_url = '<a href="/task/claim/tid=%s">%s</a>'%(task.id, "clicking here") |
|
204 |
||
205 |
notification.sub = "You have been removed from working users of %s"%task.title[:20] |
|
206 |
notification.message = "%s has removed you from the working users list of %s.<br />"%(removed_by_url, task_url) |
|
207 |
notification.message += "if you want to work on the task again, you can claim the task by %s.<br />"%claim_url |
|
208 |
if remarks: |
|
209 |
notification.remarks = remarks |
|
210 |
notification.message += "<b>Reason: </b>%s"%(remarks) |
|
211 |
||
167 | 212 |
elif role == "DL": |
213 |
||
214 |
notification.sent_from = sent_from |
|
215 |
notification.task = task |
|
216 |
deleted_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username) |
|
217 |
||
218 |
notification.sub = "Task deleted" |
|
219 |
notification.message = 'The unpublished task "%s" viewable by you has been deleted by its creator %s.<br />'%(task.title, deleted_by_url) |
|
220 |
||
221 |
if remarks: |
|
222 |
notification.remarks = remarks |
|
223 |
notification.message += "<b>Reason: </b>%s"%remarks |
|
153 | 224 |
|
199
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
225 |
elif role == "CL": |
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
226 |
|
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
227 |
notification.sent_from = sent_from |
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
228 |
notification.task = task |
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
229 |
notification.remarks = remarks |
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
230 |
|
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
231 |
claimed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username) |
201
c429873d8ac8
now there is a link to claim in new_claim notification.
nishanth
parents:
199
diff
changeset
|
232 |
claim_url = '<a href="/task/claim/tid=%s">claim</a>'%(task.id) |
199
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
233 |
task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) |
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
234 |
|
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
235 |
notification.sub = 'New claim for the task "%s"'%(task.title[:20]) |
218
59107ce0a618
Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents:
201
diff
changeset
|
236 |
notification.message = '%s has submitted a %s for the task "%s" reviewered by you.<br />'%(claimed_by_url, claim_url, task_url) |
199
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
237 |
notification.message += '<b>Claim proposal:</b> %s'%(remarks) |
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
238 |
|
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
239 |
|
946d0fe60606
now a notification is sent to all the mentors after there is a new claim.
nishanth
parents:
186
diff
changeset
|
240 |
|
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
129
diff
changeset
|
241 |
notification.save() |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
123
diff
changeset
|
242 |
|
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
243 |
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
|
244 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
245 |
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
|
246 |
arguments: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
247 |
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
|
248 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
249 |
try: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
|
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
257 |
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
|
258 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
259 |
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
|
260 |
arguments: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
261 |
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
|
262 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
263 |
try: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
return False |
123 | 267 |
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
|
268 |
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
|
269 |
return True |
123 | 270 |
|
271 |
def get_notification(nid, user): |
|
272 |
""" if notification exists, and belongs to the current user, return it. |
|
273 |
else return None. |
|
274 |
""" |
|
275 |
||
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
276 |
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
|
277 |
current_notifications = user_notifications.filter(id=nid) |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
278 |
if user_notifications: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
279 |
current_notification = current_notifications[0] |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
280 |
|
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
281 |
try: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
282 |
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
|
283 |
newest_notification = user_notifications.reverse()[0] |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
284 |
if newest_notification == newer_notification: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
285 |
newest_notification = None |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
286 |
except Notification.DoesNotExist: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
287 |
newest_notification, newer_notification = None, None |
123 | 288 |
|
133
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
289 |
try: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
290 |
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
|
291 |
oldest_notification = user_notifications[0] |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
292 |
if oldest_notification == older_notification: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
293 |
oldest_notification = None |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
294 |
except: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
295 |
oldest_notification, older_notification = None, None |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
296 |
|
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
297 |
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
|
298 |
|
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
299 |
else: |
34187a80d279
added next and previous capabilities to requests and notifications.
nishanth
parents:
132
diff
changeset
|
300 |
return None, None, None, None, None |