pytask/taskapp/utilities/notification.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Thu, 06 Jan 2011 19:07:04 +0530
branchbuildout
changeset 227 3c8f3b0e5b00
permissions -rw-r--r--
Add support for buildout and move the files to the directory to support buildout structure.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
227
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
from datetime import datetime
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
from django.contrib.auth.models import User
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
from pytask.taskapp.models import Notification, RIGHTS_CHOICES
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remarks=None, requested_by=None, receiving_user=None, pynts=None):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
    creates a notification based on the passed arguments.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
        role: role of the notification - look at choices in models 
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
        sent_to: a user to which the notification is to be sent
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
        sent_from : a user from which the message has originated
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
            A user who approves/rejects in case of request
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
            A mentor who closes/complets the task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
        reply: A boolean
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
        task: a task if applicable
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
        requested_by: a user makes the request
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
            A mentor who assigns credits in case of pynts
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
            A mentor who requests to act as a mentor
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
        remarks: any remarks for rejecting
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
        receiving_user: user receiving pynts
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
        pynts: the obvious
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
    notification = Notification(sent_date = datetime.now())
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
    notification.role = role
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
    notification.sent_to = sent_to
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
    notification.save()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
    if role == "PY":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
        notification.pynts = pynts
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
        task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
        credits_url = '<a href="/task/assigncredits/tid=%s">%s</a>'%(task.id, "click here")
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
        mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
        admin_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
        user_url = '<a href="/user/view/uid=%s">%s</a>'%(receiving_user.id, receiving_user.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
        if reply:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
            notification.sub = "Approved request for assign of credits for %s"%task.title[:20]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
            notification.message  = """ Request made by %s to assign %s pynts to %s for the task %s has been approved by %s<br />
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
                                    %s if you want the view/assign pynts page of the task.<br />"""%(mentor_url, pynts, user_url, task_url, admin_url, credits_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
        else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
            notification.sub = "Rejected request for assign of credits for %s"%task.title[:20]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
            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)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
            if remarks:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
                notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
                notification.message += "Reason: %s<br />"%remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
            notification.message += "<br />"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    elif role == "MT":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
        task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
        requested_mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
        new_mentor = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
        new_mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(new_mentor.id, new_mentor.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
        
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
        if reply:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
            notification.sub = "New mentor for the task %s"%task.title[:20]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
            notification.message = "%s has accepted the request made by %s, asking him act as a mentor for the task %s<br />"%(new_mentor_url, requested_mentor_url, task_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
            notification.message += "He can be contacted on %s"%new_mentor.email
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
        else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
            notification.sub = "%s rejected request to act as a mentor"%new_mentor.username
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
            notification.message = "%s has rejected your request asking him to act as a mentor for %s.<br />"%(new_mentor_url, task_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
            if remarks:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
                notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
                notification.message += "Remarks: %s<br />"%remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
    elif role in ["DV", "MG", "AD"]:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
        accepting_user = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    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
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
        requested_by_url = '<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
        role_rights = dict(RIGHTS_CHOICES)[role]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
        role_learn_url = "/about/%s"%role_rights.lower()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
        a_or_an = "an" if role_rights == "AD" else "a"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
        if reply:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
            notification.sub = "New %s for the site"%role_rights
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    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)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
        else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
            notification.sub = "Rejected your request to act as %s"%role_rights
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
            notification.message = "%s has rejected your request asking him to act as %s %s.<br />"%(user_url, a_or_an, role_rights)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
            if remarks:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
                notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
                notification.message += "Remarks: %s<br />"%remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
    elif role == "NT":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
        new_mentor = sent_to
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
        mentor_learn_url = '<sup><a href="/about/mentor/">learn more</a></sup>'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
        task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
        notification.sub = "You are mentoring the task %s"%task.title[:20]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
        notification.message = "You have accepted to act as a mentor%s for the task %s.<br />"%(mentor_learn_url, task_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
        notification.message += " Here is a list of other mentors and their email addresses.<br /> <ul>"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
        for a_mentor in task.mentors.exclude(id=new_mentor.id):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
            notification.message += "<li> %s - %s </li>"%(a_mentor.username, a_mentor.email)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
        notification.message += "</ul>"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
        working_users = task.assigned_users.all()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
        if working_users:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
            notification.message += "List of users working on the task.<br />"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
            notification.message += "<ul>"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
            for a_user in working_users:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
                notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
            notification.message += "</ul><br />"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
        notification.message += "Happy Mentoring."
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
    elif role == "NU":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
        start_here_url = '<a href="/about/starthere/" taget="_blank">click here</a>'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
        notification.sub = "Welcome %s"%sent_to.username
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
        notification.message = "Welcome to PyTasks %s.<br />"%sent_to.username
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
        notification.message += "%s to know more."%start_here_url
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
    elif role in ["ND", "NG", "NA"]:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
        rights_dict = dict(RIGHTS_CHOICES)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
        if role == "ND":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
            role_rights = rights_dict["DV"]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
        elif role == "NG":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
            role_rights = rights_dict["MG"]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
        elif role == "NA":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
            role_rights = rights_dict["AD"]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
        requested_by_url = r'<a href="/user/view/uid=%s">%s</a>'%(requested_by.id, requested_by.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
        role_learn_url = r'<a href="/about/%s" target="_blank">click here</a>'%role_rights.lower()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
        a_or_an = "an" if role_rights == "Admin" else "a"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
        notification.sub = "You are now %s %s"%(a_or_an, role_rights)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
        notification.message = r"You have accepted the request made by %s asking you to act as %s %s in the site "%(requested_by_url, a_or_an, role_rights)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
        notification.message += "and you are now %s %s in the site.<br /> %s to learn more on %s."%(a_or_an, role_rights, role_learn_url, role_rights)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
    elif role in ["CM", "CD"]:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
        notification.role = role
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
        notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
        mentor = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
        mentor_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
        task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
        
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
        if role == "CM":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
            notification.sub = "%s has been marked complete"%task.title
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
            notification.message = "The task %s has been marked complete by %s.<br />"%(task_url, mentor_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
        elif role == "CD":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
            notification.sub = "%s has been closed"%task.title
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
            notification.message = "The task %s has been closed by %s.<br />"%(task_url, mentor_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
        if remarks:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
            notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
            notification.message += "<b>Remarks:</b> %s"%remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
    elif role == "AU":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
        added_user = sent_to
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
        mentor = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
        assigned_by_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
        task_url= '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
        notification.sub = "Your claim for the task %s accepted."%task.title[:20]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
        notification.message = "You have been selected to work on the task %s by %s.<br />"%(task_url, assigned_by_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
        notification.message += "You can now start working on the task and will be credited by the mentors for your work.<br />"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
        notification.message += " Here is a list of mentors for the task and their email addresses.<br /> <ul>"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
        for a_mentor in task.mentors.all():
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
            notification.message += "<li> %s - %s </li>"%(a_mentor.username, a_mentor.email)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
        notification.message += "</ul>"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
        working_users = task.assigned_users.exclude(id=added_user.id)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
        if working_users:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
            notification.message += "List of other users working on the task.<br />"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
            notification.message += "<ul>"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
            for a_user in working_users:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
                notification.message += "<li> %s - %s </li>"%(a_user.username, a_user.email)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
            notification.message += "</ul><br />"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
    elif role == "RU":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
        removed_user = sent_to
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
        mentor = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
        removed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
        task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
        claim_url = '<a href="/task/claim/tid=%s">%s</a>'%(task.id, "clicking here")
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
        notification.sub = "You have been removed from working users of %s"%task.title[:20]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
        notification.message = "%s has removed you from the working users list of %s.<br />"%(removed_by_url, task_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
        notification.message += "if you want to work on the task again, you can claim the task by %s.<br />"%claim_url
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
        if remarks:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
            notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
            notification.message += "<b>Reason: </b>%s"%(remarks)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
    elif role == "DL":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
        deleted_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
        notification.sub = "Task deleted"
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
        notification.message = 'The unpublished task "%s" viewable by you has been deleted by its creator %s.<br />'%(task.title, deleted_by_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
        if remarks:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
            notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
            notification.message += "<b>Reason: </b>%s"%remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
    elif role == "CL":
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
        notification.sent_from = sent_from
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
        notification.task = task
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
        notification.remarks = remarks
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
        claimed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
        claim_url = '<a href="/task/claim/tid=%s">claim</a>'%(task.id)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
        task_url = '<a href="/task/view/tid=%s">%s</a>'%(task.id, task.title)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
        notification.sub = 'New claim for the task "%s"'%(task.title[:20])
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
        notification.message = '%s has submitted a %s for the task "%s" mentored by you.<br />'%(claimed_by_url, claim_url, task_url)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
        notification.message += '<b>Claim proposal:</b> %s'%(remarks)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
    notification.save()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
def mark_notification_read(notification_id):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
    makes a notification identified by the notification_id read.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
    arguments:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
        notification_id - a number denoting the id of the Notification object
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
    try:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
        notification = Notification.objects.get(id = notification_id)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   251
    except Notification.DoesNotExist:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
        return False
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
    notification.is_read = True
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
    notification.save()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
    return True
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
def delete_notification(notification_id):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
    deletes a notification identified by the notification_id.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
    arguments:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   261
        notification_id - a number denoting the id of the Notification object
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   263
    try:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
        notification = Notification.objects.get(id = notification_id)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
    except Notification.DoesNotExist:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
        return False
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
    notification.is_deleted = True
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
    notification.save()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
    return True
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   270
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   271
def get_notification(nid, user):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   272
    """ if notification exists, and belongs to the current user, return it.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
    else return None.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
    """
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   276
    user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   277
    current_notifications = user_notifications.filter(id=nid)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   278
    if user_notifications:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   279
        current_notification = current_notifications[0]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
        try:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   282
            newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
            newest_notification = user_notifications.reverse()[0]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   284
            if newest_notification == newer_notification:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   285
                newest_notification = None
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   286
        except Notification.DoesNotExist:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   287
            newest_notification, newer_notification = None, None
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   288
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   289
        try:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   290
            older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
            oldest_notification = user_notifications[0]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   292
            if oldest_notification == older_notification:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
                oldest_notification = None
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
        except:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   295
            oldest_notification, older_notification = None, None
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   296
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
        return newest_notification, newer_notification, current_notification, older_notification, oldest_notification
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   298
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   299
    else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   300
        return None, None, None, None, None