taskapp/utilities/notification.py
changeset 132 ca88bf4ad362
parent 131 85276c5aee5c
child 133 34187a80d279
equal deleted inserted replaced
131:85276c5aee5c 132:ca88bf4ad362
     1 from datetime import datetime
     1 from datetime import datetime
     2 from django.contrib.auth.models import User
     2 from django.contrib.auth.models import User
     3 from pytask.taskapp.models import Notification
     3 from pytask.taskapp.models import Notification, RIGHTS_CHOICES
     4 
     4 
     5 def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None):
     5 def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None):
     6     """
     6     """
     7     creates a notification based on the passed arguments.
     7     creates a notification based on the passed arguments.
     8         role: role of the notification - look at choices in models 
     8         role: role of the notification - look at choices in models 
    66             notification.sub = "Rejected request to act as a mentor for %s"%task.title[:20]
    66             notification.sub = "Rejected request to act as a mentor for %s"%task.title[:20]
    67             notification.message = "%s has rejected your request asking him to act as a mentor for %s.<br />"%(new_mentor_url, task_url)
    67             notification.message = "%s has rejected your request asking him to act as a mentor for %s.<br />"%(new_mentor_url, task_url)
    68             if remarks:
    68             if remarks:
    69                 notification.message += "Remarks: %s<br />"%remarks
    69                 notification.message += "Remarks: %s<br />"%remarks
    70 
    70 
       
    71     elif role in ["DV", "MG", "AD"]:
       
    72 
       
    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
       
    75         requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id,requested_by.username)
       
    76         role_rights = dict(RIGHTS_CHOICES)[role]
       
    77         role_learn_url = "/about/%s"%role_rights.lower()
       
    78         a_or_an = "an" if role == "AD" else "a"
       
    79 
       
    80         if reply:
       
    81             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)
       
    83         else:
       
    84             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)
       
    86             if remarks:
       
    87                 notification.message += "Remarks: %s<br />"%remarks
    71 
    88 
    72     elif role == "NT":
    89     elif role == "NT":
    73 
    90 
    74         new_mentor = sent_to
    91         new_mentor = sent_to
    75         mentor_learn_url = '<sup><a href="/about/mentor">learn more</a></sup>'
    92         mentor_learn_url = '<sup><a href="/about/mentor">learn more</a></sup>'