From 6b2d9faeb5827ddfb1d6ab9ec1ff341d24a18b1a Mon Sep 17 00:00:00 2001
From: nishanth
Date: Sat, 27 Feb 2010 14:22:26 +0530
Subject: notifications work for approving and rejecting credits.
---
taskapp/utilities/notification.py | 44 +++++++++++++++++++++++++++++----------
1 file changed, 33 insertions(+), 11 deletions(-)
(limited to 'taskapp/utilities/notification.py')
diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py
index 5d1d994..9b88012 100644
--- a/taskapp/utilities/notification.py
+++ b/taskapp/utilities/notification.py
@@ -2,19 +2,46 @@ from datetime import datetime
from django.contrib.auth.models import User
from pytask.taskapp.models import Notification
-def create_notification(to,subject,message):
+def create_notification(role, sent_to, sent_from=None, reply=None, task=None, receiving_user=None, pynts=None, requested_by=None, remarks=None):
"""
creates a notification based on the passed arguments.
to - a list of users to which the notification is to be sent
subject - subject of the notification message to be sent
message - message body of the notification
"""
+
notification = Notification(sent_date = datetime.now())
+ notification.role = role
+ notification.sent_to = sent_to
notification.save()
- notification.sent_to = to
- notification.sub = subject
- notification.message = message
- notification.save()
+
+ if role == "PY":
+
+ notification.sent_from = sent_from
+ notification.task = task
+ notification.pynts = pynts
+
+ task_url= '%s'%(task.id, task.title)
+ credits_url = '%s'%(task.id, "click here")
+ mentor_url = '%s'%(requested_by.id, requested_by.username)
+ admin_url = '%s'%(sent_from.id, sent_from.username)
+ user_url = '%s'%(receiving_user.id, receiving_user.username)
+
+ if reply:
+ notification.sub = "Approved request for assign of credits"
+ notification.message = """ Request made by %s to assign %s pynts to %s for the task %s has been approved by %s
+ %s if you want the view/assign pynts page of the task.
"""%(mentor_url, pynts, user_url, task_url, admin_url, credits_url)
+
+ else:
+ notification.sub = "Rejected request for assign of credits"
+ notification.message = """ Request made by %s to assign %s pynts to %s for the task %s has been rejected by %s.
"""%(mentor_url, pynts, user_url, task_url, admin_url)
+ if remarks:
+ notification.remarks = remarks
+ notification.message += "Reason: %s
"%remarks
+ notification.message += "
"
+
+ notification.save()
+
def mark_notification_read(notification_id):
"""
@@ -54,10 +81,5 @@ def get_notification(nid, user):
except Notification.DoesNotExist:
return None
- try:
- notify_obj.sent_to.get(id=user.id)
- except User.DoesNotExist:
- return None
-
- if not notify_obj.is_deleted:
+ if notify_obj.sent_to == user and ( not notify_obj.is_deleted ):
return notify_obj
--
cgit