taskapp/events/task.py
author Nishanth Amuluru <nishanth@fossee.in>
Wed, 05 Jan 2011 22:30:45 +0530
changeset 219 f04a1ec7a07f
parent 218 59107ce0a618
permissions -rw-r--r--
Replaced the word credit with pynt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     1
from datetime import datetime
205
0c317f68df49 ditchaxed the claims model.
nishanth
parents: 199
diff changeset
     2
from pytask.taskapp.models import Profile, Task, Comment, Map
120
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents: 119
diff changeset
     3
from pytask.taskapp.utilities.task import getTask
99
64c34c1f441f assign_credits event now creates a proper request object .
nishanth
parents: 96
diff changeset
     4
from pytask.taskapp.utilities.request import create_request
119
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
     5
from pytask.taskapp.utilities.helper import get_key
131
85276c5aee5c added notifications for approval and rejection of a mentor.
nishanth
parents: 126
diff changeset
     6
from pytask.taskapp.utilities.notification import create_notification
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     7
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
     8
def publishTask(task, rem_reviewers=True, rem_comments=True):
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     9
    """ set the task status to open """
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    10
189
8f5fb15ffd9b fixed a bug in publish task.
nishanth
parents: 167
diff changeset
    11
 #   if task.sub_type == 'D':
8f5fb15ffd9b fixed a bug in publish task.
nishanth
parents: 167
diff changeset
    12
     #      deps, subs = task.map_subs.all(), []
8f5fb15ffd9b fixed a bug in publish task.
nishanth
parents: 167
diff changeset
    13
     #else:
8f5fb15ffd9b fixed a bug in publish task.
nishanth
parents: 167
diff changeset
    14
         #   subs, deps = task.map_subs.all(), []
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    15
   
189
8f5fb15ffd9b fixed a bug in publish task.
nishanth
parents: 167
diff changeset
    16
    task = getTask(task.id)
8f5fb15ffd9b fixed a bug in publish task.
nishanth
parents: 167
diff changeset
    17
    if task.subs or any(map(lambda t:t.status!="CM",task.deps)):
53
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    18
        task.status = "LO"
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    19
    else:
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    20
        task.status = "OP"
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 105
diff changeset
    21
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    22
    if rem_reviewers:
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    23
        task.reviewers.clear()
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    24
        task.reviewers.add(task.created_by)
112
eadff01e395e now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents: 111
diff changeset
    25
113
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    26
    if rem_comments:
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    27
        task.comment_set.update(is_deleted=True)
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    28
        task.comment_set.update(deleted_by=task.created_by)
112
eadff01e395e now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents: 111
diff changeset
    29
125
d3cfceb8e120 homepage now displays a list of unpublished tasks
nishanth
parents: 124
diff changeset
    30
    task.published_datetime = datetime.now()
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 154
diff changeset
    31
    task.save()
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
    32
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 154
diff changeset
    33
    pending_requests = task.request_task.filter(is_valid=True, is_replied=False)
7cad1e92713d finalised the view_task page.
nishanth
parents: 154
diff changeset
    34
    pending_requests.update(is_valid=False)
7cad1e92713d finalised the view_task page.
nishanth
parents: 154
diff changeset
    35
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    36
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    37
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    38
def addSubTask(main_task, sub_task):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    39
    """ add the task to subs attribute of the task and update its status.
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
    40
    sub task can be added only if a task is in UP/OP/LO state.
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    41
    """
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    42
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    43
    ## Shall modify after talking to pr about subtasks
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    44
    ## I think i might even remove the concept of subtasks
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    45
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    46
    main_task.sub_type = "S"
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    47
    main_task.save()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    48
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    49
    try:
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    50
        mapobj = Map.objects.get(main=main_task)
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    51
    except Map.DoesNotExist:
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    52
        mapobj = Map()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    53
        mapobj.main = main_task
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    54
        mapobj.save()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    55
    mapobj.subs.add(sub_task)
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    56
    mapobj.save()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    57
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    58
    sub_tasks = getTask(main_task.id).subs
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    59
    if main_task.status == "OP":
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    60
        if any(map(lambda t:t.status!="CM",sub_tasks)):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    61
            main_task.status = "LO"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    62
        else:
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    63
            "CM"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    64
    main_task.save()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    65
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    66
def addDep(main_task, dependency):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    67
    """ add the dependency task to deps attribute of the task.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    68
    update the status of main_task accordingly.
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 74
diff changeset
    69
    note that deps can be added only if task is in UP/OP/LO state.
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    70
    And also if the task doesn't have any subs.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    71
    """
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    72
90
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    73
    main_task.sub_type = "D"
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    74
    main_task.save()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    75
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    76
    try:
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    77
        mapobj = Map.objects.get(main=main_task)
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    78
    except Map.DoesNotExist:
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    79
        mapobj = Map()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    80
        mapobj.main = main_task
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    81
        mapobj.save()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    82
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    83
    mapobj.subs.add(dependency)
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    84
    mapobj.save()
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    85
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    86
    deps = getTask(main_task.id).deps
b2426897ff18 our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents: 89
diff changeset
    87
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    88
    if main_task.status in ["OP", "LO"]: 
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    89
        if all(map(lambda t:t.status=="CM",deps)):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    90
            main_task.status = "OP"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    91
        else:
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    92
            main_task.status = "LO"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    93
    
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    94
    main_task.save()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    95
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
    96
def reqReviewer(task, reviewer, req_by):
105
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    97
    """ create a request object with role as MT.
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    98
    """
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    99
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   100
    create_request(sent_by=req_by, role="MT", sent_to=reviewer, task=task) 
105
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
   101
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   102
def addReviewer(task,reviewer):
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   103
    """ add the reviewer to reviewers list of the task """
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   104
    
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   105
    task.reviewers.add(reviewer)
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   106
    task.save()
119
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   107
    return task     
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   108
219
f04a1ec7a07f Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents: 218
diff changeset
   109
def createTask(title,desc,created_by,pynts):
f04a1ec7a07f Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents: 218
diff changeset
   110
    """ creates a bare minimum task with title, description and pynts.
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   111
    the creator of the task will be assigned as a reviewer for the task.
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   112
    """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   113
119
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   114
    while True:
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   115
        id = get_key()
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   116
        try:
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   117
            task = Task.objects.get(id__iexact=id)
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   118
            continue
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   119
        except Task.DoesNotExist:
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   120
            break
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   121
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   122
    try:
166
ac72d641046e now task can have a title of a deleted task.
nishanth
parents: 162
diff changeset
   123
        task = Task.objects.exclude(status="DL").get(title__iexact=title)
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   124
        return None
119
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   125
    except:
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   126
        task = Task(title=title)
119
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   127
39ab7c460143 did lots and now id field in task is a random key
nishanth
parents: 117
diff changeset
   128
    task.id = id 
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   129
    task.desc = desc
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   130
    task.created_by = created_by
219
f04a1ec7a07f Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents: 218
diff changeset
   131
    task.pynts = pynts
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   132
    task.creation_datetime = datetime.now()
124
6d92b7cd2a37 taking care if publish task post request is made again. added published_date field to task.
nishanth
parents: 120
diff changeset
   133
    task.published_datetime = datetime.now()
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   134
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   135
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   136
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   137
def addClaim(task, message, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   138
    """ add claim data to the database if it does not exist 
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   139
    and also update the claimed users field of the task.
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   140
    """
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   141
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   142
    task.claimed_users.add(user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   143
    task.save()
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   144
195
2717c8533322 if a user claims a task his unreplied mentor requests will be made invalid.
nishanth
parents: 189
diff changeset
   145
    pending_reqs = user.request_sent_to.filter(is_replied=False, is_valid=True, role="MT", task=task).all()
2717c8533322 if a user claims a task his unreplied mentor requests will be made invalid.
nishanth
parents: 189
diff changeset
   146
    for req in pending_reqs:
2717c8533322 if a user claims a task his unreplied mentor requests will be made invalid.
nishanth
parents: 189
diff changeset
   147
        req.is_valid = False
2717c8533322 if a user claims a task his unreplied mentor requests will be made invalid.
nishanth
parents: 189
diff changeset
   148
        req.save()
2717c8533322 if a user claims a task his unreplied mentor requests will be made invalid.
nishanth
parents: 189
diff changeset
   149
        user_url = '<a href="/user/view/uid=%s">%s</a>'%(user.id, user.username)
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   150
        reason = "User has claimed the task and hence cannot be a reviewer and this request was made invalid."
195
2717c8533322 if a user claims a task his unreplied mentor requests will be made invalid.
nishanth
parents: 189
diff changeset
   151
        create_notification("MT", req.sent_by, user, task=task, reply=False, remarks=reason, requested_by=req.sent_by)
199
946d0fe60606 now a notification is sent to all the mentors after there is a new claim.
nishanth
parents: 195
diff changeset
   152
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   153
    for a_reviewer in task.reviewers.all():
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   154
        create_notification("CL", a_reviewer, user, task=task, remarks=message)
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   155
    
162
d378eff02f2e added au ru notifications.
nishanth
parents: 158
diff changeset
   156
def assignTask(task, added_user, assigned_by):
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   157
    """ check for the status of task and assign it to the particular user """
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   158
    
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   159
    if task.status in ['OP', 'WR']:
162
d378eff02f2e added au ru notifications.
nishanth
parents: 158
diff changeset
   160
        task.assigned_users.add(added_user)
d378eff02f2e added au ru notifications.
nishanth
parents: 158
diff changeset
   161
        task.claimed_users.remove(added_user)
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   162
        task.status = "WR"
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   163
    task.save()
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   164
162
d378eff02f2e added au ru notifications.
nishanth
parents: 158
diff changeset
   165
    create_notification("AU", added_user, assigned_by, task=task)
d378eff02f2e added au ru notifications.
nishanth
parents: 158
diff changeset
   166
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   167
219
f04a1ec7a07f Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents: 218
diff changeset
   168
def updateTask(task, title=None, desc=None, pynts=None, tags_field=None):
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   169
    """ update the property accordingly.
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   170
    while updating title, check for uniqueness of title.
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   171
    return None if any error. 
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   172
    """
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   173
    
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   174
    if title:
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   175
        try:
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   176
            task.title = title
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   177
            task.save()
74
7dc764854867 fixed a bug.
nishanth
parents: 63
diff changeset
   178
        except Task.IntegrityError:
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   179
            return None
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   180
    if desc:task.desc = desc
219
f04a1ec7a07f Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents: 218
diff changeset
   181
    if pynts:task.pynts = pynts
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   182
    if tags_field:task.tags_field = tags_field
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   183
    task.save()
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   184
    return task
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   185
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   186
def removeTask(main_task, sub_task):
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   187
    """ get the corresponding map object and remove the sub_task.
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   188
    """
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   189
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   190
    mapobj = Map.objects.get(main=main_task)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   191
    mapobj.subs.remove(sub_task)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   192
    mapobj.save()
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   193
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   194
def removeUser(main_task, rem_user, removed_by, reason=None):
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   195
    """ right now, just remove the user from the list of assigned_users.
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   196
    """
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   197
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   198
    main_task.assigned_users.remove(rem_user)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   199
    main_task.save()
95
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   200
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   201
    ## TODiscuss : when a user is kicked off, his pending requests for pynts is made invalid
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   202
    rem_user.request_receiving_user.filter(task=main_task,role="PY",is_valid=True,is_replied=False).update(is_valid=False)
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   203
162
d378eff02f2e added au ru notifications.
nishanth
parents: 158
diff changeset
   204
    create_notification("RU", rem_user, removed_by, task=main_task, remarks=reason)
158
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   205
    ## TODO : create notification to the victim
c43e0114e593 removing user deletes all the pending requests that request giving him pynts.
nishanth
parents: 156
diff changeset
   206
219
f04a1ec7a07f Replaced the word credit with pynt
Nishanth Amuluru <nishanth@fossee.in>
parents: 218
diff changeset
   207
def assignPynts(task, given_by, given_to, points):
96
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   208
    """ make a proper request object.
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   209
    """
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   210
    
99
64c34c1f441f assign_credits event now creates a proper request object .
nishanth
parents: 96
diff changeset
   211
    create_request(sent_by=given_by, role="PY", task=task, receiving_user=given_to, pynts=points ) 
96
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   212
114
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   213
def completeTask(task, marked_by):
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   214
    """ set the status of task as completed.
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   215
    We dont have to inform parent tasks.
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   216
    That part is taken care by getTask method.
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   217
    """
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   218
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   219
    task.status = "CM"
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   220
    task.save()
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   221
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   222
    pending_requests = task.request_task.filter(is_replied=False)
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   223
    pending_requests.update(is_valid=False)
117
58fa1d626d37 now if a task is closed/completed all its pending requests will be made invalid.
nishanth
parents: 114
diff changeset
   224
114
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   225
    ## generate notification appropriately using marked_by
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   226
    ## we also have to mark unread requests as invalid
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   227
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   228
    for a_user in task.assigned_users.all():
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   229
        create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task)
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   230
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   231
    for a_user in task.claimed_users.all():
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   232
        create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task)
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   233
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   234
    for a_reviewer in task.reviewers.all():
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   235
        create_notification(role="CM", sent_to=a_reviewer, sent_from=marked_by, task=task)
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   236
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   237
def closeTask(task, closed_by, reason=None):
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   238
    """ set the status of task as CD.
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   239
    generate notifications accordingly.
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   240
    """
114
38793914921b mark task as complete functionality is added.
nishanth
parents: 113
diff changeset
   241
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   242
    task.status = "CD"
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   243
    task.save()
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   244
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   245
    pending_requests = task.request_task.filter(is_replied=False)
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   246
    pending_requests.update(is_valid=False)
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   247
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   248
    ## generate notifications here
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   249
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   250
    for a_user in task.assigned_users.all():
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 154
diff changeset
   251
        create_notification(role="CD", sent_to=a_user, sent_from=closed_by, task=task, remarks=reason)
126
e5377fdaf110 added the functionality to close a task.
nishanth
parents: 125
diff changeset
   252
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   253
    for a_user in task.claimed_users.all():
156
7cad1e92713d finalised the view_task page.
nishanth
parents: 154
diff changeset
   254
        create_notification(role="CD", sent_to=a_user, sent_from=closed_by, task=task, remarks=reason)
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   255
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   256
    for a_reviewer in task.reviewers.all():
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   257
        create_notification(role="CD", sent_to=a_reviewer, sent_from=closed_by, task=task, remarks=reason)
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   258
167
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   259
def deleteTask(task, deleted_by, reason=None):
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   260
    """ set the task status as DL
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   261
    notify all its other viewers about the deleting of task.
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   262
    """
153
925af1b4ee65 ditchaxed credit model.
nishanth
parents: 131
diff changeset
   263
167
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   264
    task.status = "DL"
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   265
    task.save()
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   266
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   267
    pending_requests = task.request_task.filter(is_replied=False,is_valid=True)
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   268
    pending_requests.update(is_valid=False)
b61e45074ba1 implemented deleting of a task.
nishanth
parents: 166
diff changeset
   269
218
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   270
    for a_reviewer in task.reviewers.exclude(id=deleted_by.id):
59107ce0a618 Replaced the word mentor with reviewer
Nishanth Amuluru <nishanth@fossee.in>
parents: 205
diff changeset
   271
        create_notification("DL", sent_to=a_reviewer, sent_from=deleted_by, task=task, remarks=reason)