diff options
-rw-r--r-- | taskapp/events/request.py | 25 | ||||
-rw-r--r-- | taskapp/models.py | 6 | ||||
-rw-r--r-- | taskapp/utilities/notification.py | 44 | ||||
-rw-r--r-- | templates/user/view_notification.html | 10 |
4 files changed, 57 insertions, 28 deletions
diff --git a/taskapp/events/request.py b/taskapp/events/request.py index a104b8e..0bc1de0 100644 --- a/taskapp/events/request.py +++ b/taskapp/events/request.py @@ -1,6 +1,7 @@ from datetime import datetime from pytask.taskapp.events.task import addCredits, addMentor from pytask.taskapp.events.user import changeRole +from pytask.taskapp.utilities.notification import create_notification def reply_to_request(request_obj, reply, replied_by): """ @@ -18,15 +19,21 @@ def reply_to_request(request_obj, reply, replied_by): request_obj.save() if request_obj.role == "PY": - if reply: - ## note that we are not checking if he is stilla mentor - ## since we are not allowing removing mentors - ## if we allow, we have complications like removing unreplied requests made by this mentor and stuff. - ## but we check if this user is still an admin and put a notification if that you are no longer an admin and hence cannot do this. - addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts) - print "send yes notifications appropriately" - else: - print "send a no notificvaton" + ## note that we are not doing any check. we make requests invalid when an event like closing task happens. + task = request_obj.task + pynts = request_obj.pynts + receiving_user = request_obj.receiving_user + requested_by = request_obj.sent_by + for a_mentor in task.mentors.all(): + if reply: + addCredits(task, request_obj.sent_by, request_obj.receiving_user, pynts) + print "send yes notifications appropriately" + #def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remark=None, receiving_user=None, pynts=None, requested_by): + create_notification("PY", a_mentor, replied_by, True, task, receiving_user, pynts, requested_by) + else: + print "send a no notificvaton" + create_notification("PY", a_mentor, replied_by, False, task, receiving_user, pynts, requested_by, request_obj.remarks) + elif request_obj.role == "MT": ## add him as a mentor to the task if reply: diff --git a/taskapp/models.py b/taskapp/models.py index bc655b9..65db018 100644 --- a/taskapp/models.py +++ b/taskapp/models.py @@ -172,13 +172,13 @@ class Notification(models.Model): role = models.CharField(max_length = 2, choices = NOTIFY_CHOICES, blank = False) sent_to = models.ForeignKey(User, related_name = "%(class)s_sent_to", blank = False) - sent_from = models.ForeignKey(User, related_name = "%(class)s_sent_from", blank = True) - task = models.ForeignKey(Task, related_name = "%(class)s_sent_for", blank = False) + sent_from = models.ForeignKey(User, related_name = "%(class)s_sent_from", null = True, blank = True) + task = models.ForeignKey(Task, related_name = "%(class)s_sent_for", null = True, blank = True) sub = models.CharField(max_length = 100) message = models.TextField() - remark = models.CharField(max_length = 100) + remarks = models.CharField(max_length = 100) sent_date = models.DateTimeField() is_read = models.BooleanField(default = False) 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= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title) + credits_url = '<a href="/task/assigncredits/tid=%s">%s</a>'%(task.id, "click here") + mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username) + admin_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username) + user_url = '<a href="/user/view/uid=%s">%s</a>'%(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<br /> + %s if you want the view/assign pynts page of the task.<br />"""%(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.<br /> """%(mentor_url, pynts, user_url, task_url, admin_url) + if remarks: + notification.remarks = remarks + notification.message += "Reason: %s<br />"%remarks + notification.message += "<br />" + + 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 diff --git a/templates/user/view_notification.html b/templates/user/view_notification.html index f31eed9..278a362 100644 --- a/templates/user/view_notification.html +++ b/templates/user/view_notification.html @@ -1,10 +1,10 @@ {% extends 'base.html' %} {% block content %} - Subject: {{notification.sub}}<br /> - Sent time: {{notification.sent_date}}<br /> - {% autoescape off %} - {{notification.message}} - {% endautoescape %} + sent at {{notification.sent_date}}<br /> + Sub: {{notification.sub}}<br /> + + <br /> + {{notification.message|safe}} <form action="delete/" method="post"> <input type="submit" value="Delete"> </form> <form action="unread/" method="post"> <input type="submit" value="Keep Unread"> </form> {% endblock %} |