69 notification.message += "Remarks: %s<br />"%remarks |
69 notification.message += "Remarks: %s<br />"%remarks |
70 |
70 |
71 elif role in ["DV", "MG", "AD"]: |
71 elif role in ["DV", "MG", "AD"]: |
72 |
72 |
73 accepting_user = sent_from |
73 accepting_user = sent_from |
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 |
74 user_url = "/user/view/uid=%s"%(accepting_user.id) ## i mean the user who has accepted it |
75 requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id,requested_by.username) |
75 requested_by_url = "/user/view/uid=%s"%(requested_by.id) |
76 role_rights = dict(RIGHTS_CHOICES)[role] |
76 role_rights = dict(RIGHTS_CHOICES)[role] |
77 role_learn_url = "/about/%s"%role_rights.lower() |
77 role_learn_url = "/about/%s"%role_rights.lower() |
78 a_or_an = "an" if role == "AD" else "a" |
|
79 |
78 |
80 if reply: |
79 if reply: |
81 notification.sub = "New %s for the site"%role_rights |
80 notification.sub = "New %s for the site"%role_rights |
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) |
81 notification.message = "%s has accepted request made by %s asking him to act as a %s for the website.<br />"(user_url, requested_by_url, role_rights) |
83 else: |
82 else: |
84 notification.sub = "Rejected your request to act as %s"%role_rights |
83 notification.sub = "Rejected your request to act as %s"%role_rights |
85 notification.message = "%s has rejected your request asking him to act as %s %s for the website.<br />"%(user_url, a_or_an, role_rights) |
84 notification.message = "%s has rejected your request asking him to act as a %s.<br />"%(new_mentor_url, task_url) |
86 if remarks: |
85 if remarks: |
87 notification.message += "Remarks: %s<br />"%remarks |
86 notification.message += "Remarks: %s<br />"%remarks |
88 |
87 |
89 elif role == "NT": |
88 elif role == "NT": |
90 |
89 |
107 notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email) |
106 notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email) |
108 notification.message += "</ul><br />" |
107 notification.message += "</ul><br />" |
109 notification.message += "Happy Mentoring." |
108 notification.message += "Happy Mentoring." |
110 |
109 |
111 notification.save() |
110 notification.save() |
112 |
|
113 |
111 |
114 def mark_notification_read(notification_id): |
112 def mark_notification_read(notification_id): |
115 """ |
113 """ |
116 makes a notification identified by the notification_id read. |
114 makes a notification identified by the notification_id read. |
117 arguments: |
115 arguments: |
142 def get_notification(nid, user): |
140 def get_notification(nid, user): |
143 """ if notification exists, and belongs to the current user, return it. |
141 """ if notification exists, and belongs to the current user, return it. |
144 else return None. |
142 else return None. |
145 """ |
143 """ |
146 |
144 |
147 try: |
145 user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date') |
148 notify_obj = Notification.objects.get(id=nid) |
146 current_notifications = user_notifications.filter(id=nid) |
149 except Notification.DoesNotExist: |
147 if user_notifications: |
150 return None |
148 current_notification = current_notifications[0] |
151 |
149 |
152 if notify_obj.sent_to == user and ( not notify_obj.is_deleted ): |
150 try: |
153 return notify_obj |
151 newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False) |
|
152 newest_notification = user_notifications.reverse()[0] |
|
153 if newest_notification == newer_notification: |
|
154 newest_notification = None |
|
155 except Notification.DoesNotExist: |
|
156 newest_notification, newer_notification = None, None |
|
157 |
|
158 try: |
|
159 older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False) |
|
160 oldest_notification = user_notifications[0] |
|
161 if oldest_notification == older_notification: |
|
162 oldest_notification = None |
|
163 except: |
|
164 oldest_notification, older_notification = None, None |
|
165 |
|
166 return newest_notification, newer_notification, current_notification, older_notification, oldest_notification |
|
167 |
|
168 else: |
|
169 return None, None, None, None, None |