taskapp/utilities/notification.py
changeset 162 d378eff02f2e
parent 161 74ef330c9185
child 167 b61e45074ba1
equal deleted inserted replaced
161:74ef330c9185 162:d378eff02f2e
    67 
    67 
    68         else:
    68         else:
    69             notification.sub = "%s rejected request to act as a mentor"%new_mentor.username
    69             notification.sub = "%s rejected request to act as a mentor"%new_mentor.username
    70             notification.message = "%s has rejected your request asking him to act as a mentor for %s.<br />"%(new_mentor_url, task_url)
    70             notification.message = "%s has rejected your request asking him to act as a mentor for %s.<br />"%(new_mentor_url, task_url)
    71             if remarks:
    71             if remarks:
       
    72                 notification.remarks = remarks
    72                 notification.message += "Remarks: %s<br />"%remarks
    73                 notification.message += "Remarks: %s<br />"%remarks
    73 
    74 
    74     elif role in ["DV", "MG", "AD"]:
    75     elif role in ["DV", "MG", "AD"]:
    75 
    76 
    76         notification.sent_from = sent_from
    77         notification.sent_from = sent_from
    77 
       
    78         accepting_user = sent_from
    78         accepting_user = sent_from
    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
    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
    80         requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
    80         requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
    81         role_rights = dict(RIGHTS_CHOICES)[role]
    81         role_rights = dict(RIGHTS_CHOICES)[role]
    82         role_learn_url = "/about/%s"%role_rights.lower()
    82         role_learn_url = "/about/%s"%role_rights.lower()
    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)
    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)
    88         else:
    88         else:
    89             notification.sub = "Rejected your request to act as %s"%role_rights
    89             notification.sub = "Rejected your request to act as %s"%role_rights
    90             notification.message = "%s has rejected your request asking him to act as %s %s.<br />"%(user_url, a_or_an, role_rights)
    90             notification.message = "%s has rejected your request asking him to act as %s %s.<br />"%(user_url, a_or_an, role_rights)
    91             if remarks:
    91             if remarks:
       
    92                 notification.remarks = remarks
    92                 notification.message += "Remarks: %s<br />"%remarks
    93                 notification.message += "Remarks: %s<br />"%remarks
    93 
    94 
    94     elif role == "NT":
    95     elif role == "NT":
    95 
    96 
    96         notification.task = task
    97         notification.task = task
   160         elif role == "CD":
   161         elif role == "CD":
   161             notification.sub = "%s has been closed"%task.title
   162             notification.sub = "%s has been closed"%task.title
   162             notification.message = "The task %s has been closed by %s.<br />"%(task_url, mentor_url)
   163             notification.message = "The task %s has been closed by %s.<br />"%(task_url, mentor_url)
   163 
   164 
   164         if remarks:
   165         if remarks:
       
   166             notification.remarks = remarks
   165             notification.message += "<b>Remarks:</b> %s"%remarks
   167             notification.message += "<b>Remarks:</b> %s"%remarks
       
   168 
       
   169     elif role == "AU":
       
   170 
       
   171         notification.task = task
       
   172         added_user = sent_to
       
   173         mentor = sent_from
       
   174         assigned_by_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username)
       
   175         task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
       
   176 
       
   177         notification.sub = "Your claim for the task %s accepted."%task.title[:20]
       
   178         notification.message = "You have been selected to work on the task %s by %s.<br />"%(task_url, assigned_by_url)
       
   179         notification.message += "You can now start working on the task and will be credited by the mentors for your work.<br />"
       
   180 
       
   181         notification.message += " Here is a list of mentors for the task and their email addresses.<br /> <ul>"
       
   182         for a_mentor in task.mentors.all():
       
   183             notification.message += "<li> %s - %s </li>"%(a_mentor.username, a_mentor.email)
       
   184         notification.message += "</ul>"
       
   185 
       
   186         working_users = task.assigned_users.exclude(id=added_user.id)
       
   187         if working_users:
       
   188             notification.message += "List of other users working on the task.<br />"
       
   189             notification.message += "<ul>"
       
   190             for a_user in working_users:
       
   191                 notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email)
       
   192             notification.message += "</ul><br />"
       
   193 
       
   194     elif role == "RU":
       
   195 
       
   196         notification.task = task
       
   197         removed_user = sent_to
       
   198         mentor = sent_from
       
   199         removed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username)
       
   200         task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
       
   201         claim_url = '<a href="/task/claim/tid=%s">%s</a>'%(task.id, "clicking here")
       
   202 
       
   203         notification.sub = "You have been removed from working users of %s"%task.title[:20]
       
   204         notification.message = "%s has removed you from the working users list of %s.<br />"%(removed_by_url, task_url)
       
   205         notification.message += "if you want to work on the task again, you can claim the task by %s.<br />"%claim_url
       
   206         if remarks:
       
   207             notification.remarks = remarks
       
   208             notification.message += "<b>Reason: </b>%s"%(remarks)
   166 
   209 
   167 
   210 
   168     notification.save()
   211     notification.save()
   169 
   212 
   170 def mark_notification_read(notification_id):
   213 def mark_notification_read(notification_id):