taskapp/events/task.py
author nishanth
Fri, 26 Feb 2010 11:34:17 +0530
changeset 113 ea962d5fe99e
parent 112 eadff01e395e
child 114 38793914921b
permissions -rw-r--r--
added option of specifying if previous mentors and comments must be removed in publish task event.
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
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
     2
from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map
99
64c34c1f441f assign_credits event now creates a proper request object .
nishanth
parents: 96
diff changeset
     3
from pytask.taskapp.utilities.request import create_request
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     4
113
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
     5
def publishTask(task, rem_mentors=True, rem_comments=True):
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     6
    """ 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
     7
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
     8
    if 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
     9
        deps, subs = task.map_subs.all(), []
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
    else:
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
    11
        subs, deps = task.map_subs.all(), []
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
    12
   
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
    13
    if subs or any(map(lambda t:t.status!="CM",deps)):
53
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    14
        task.status = "LO"
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    15
    else:
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    16
        task.status = "OP"
111
c272d4c601cd added the functionality to publish a task.
nishanth
parents: 105
diff changeset
    17
113
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    18
    if rem_mentors:
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    19
        task.mentors.clear()
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    20
        task.mentors.add(task.created_by)
112
eadff01e395e now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents: 111
diff changeset
    21
113
ea962d5fe99e added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents: 112
diff changeset
    22
    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
    23
        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
    24
        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
    25
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    26
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    27
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    28
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    29
def addSubTask(main_task, sub_task):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    30
    """ 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
    31
    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
    32
    """
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    33
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    34
    ## Shall modify after talking to pr about subtasks
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    35
    ## 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
    36
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
    37
    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
    38
    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
    39
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
    40
    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
    41
        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
    42
    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
    43
        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
    44
        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
    45
        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
    46
    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
    47
    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
    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
    sub_tasks = getTask(main_task.id).subs
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    50
    if main_task.status == "OP":
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    51
        if any(map(lambda t:t.status!="CM",sub_tasks)):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    52
            main_task.status = "LO"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    53
        else:
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    54
            "CM"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    55
    main_task.save()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    56
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    57
def addDep(main_task, dependency):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    58
    """ add the dependency task to deps attribute of the task.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    59
    update the status of main_task accordingly.
89
1cc03941ed5d added the capability of adding subtasks/dependencies .
nishanth
parents: 74
diff changeset
    60
    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
    61
    And also if the task doesn't have any subs.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    62
    """
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    63
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
    64
    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
    65
    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
    66
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
    67
    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
    68
        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
    69
    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
    70
        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
    71
        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
    72
        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
    73
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
    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
    75
    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
    76
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
    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
    78
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    79
    if main_task.status in ["OP", "LO"]: 
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    80
        if all(map(lambda t:t.status=="CM",deps)):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    81
            main_task.status = "OP"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    82
        else:
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    83
            main_task.status = "LO"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    84
    
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    85
    main_task.save()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    86
105
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    87
def reqMentor(task, mentor, req_by):
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    88
    """ 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
    89
    """
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    90
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    91
    create_request(sent_by=req_by, role="MT", sent_to=mentor, task=task) 
091b044a3bf4 now adding mentor for a task happens through request. notifications still pending though
nishanth
parents: 99
diff changeset
    92
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    93
def addMentor(task,mentor):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    94
    """ add the mentor to mentors list of the task """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    95
    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    96
    task.mentors.add(mentor)
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    97
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    98
    return task    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    99
    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   100
def createTask(title,desc,created_by,credits):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   101
    """ creates a bare minimum task with title, description and credits.
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   102
    the creator of the task will be assigned as a mentor for the task.
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   103
    """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   104
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   105
    try:
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
   106
        task = Task.objects.get(title__iexact=title)
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   107
        return None
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   108
    except Task.DoesNotExist:
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   109
        task = Task(title=title)
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   110
    task.desc = desc
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   111
    task.created_by = created_by
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   112
    task.credits = credits
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   113
    task.creation_datetime = datetime.now()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   114
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   115
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
   116
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   117
def addClaim(task, message, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   118
    """ 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
   119
    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
   120
    """
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   121
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   122
    task.claimed_users.add(user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   123
    task.save()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   124
    claim = Claim()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   125
    claim.message = message
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   126
    claim.task = task
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   127
    claim.user = user
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   128
    claim.creation_datetime = datetime.now()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   129
    claim.save()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   130
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   131
def assignTask(task, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   132
    """ 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
   133
    
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   134
    if task.status in ['OP', 'WR']:
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   135
        task.assigned_users.add(user)
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   136
        task.claimed_users.remove(user)
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   137
        task.status = "WR"
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   138
    task.save()
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   139
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   140
def getTask(tid):
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   141
    """ retreive the task from database.
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   142
    if the task has deps or subs, update its status correspondingly.
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   143
    """
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   144
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   145
    task = Task.objects.get(id=tid)
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
   146
    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
   147
        mapobj = Map.objects.get(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
   148
    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
   149
        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
   150
        mapobj.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
   151
        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
   152
        
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
   153
    task_subs = mapobj.subs.all()
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   154
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
   155
    if 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
   156
        task.deps, task.subs = task_subs, []
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
   157
    elif 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
   158
        task.subs, task.deps = task_subs, []
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
   159
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
   160
    deps, subs = task.deps, task.subs
55
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   161
    if deps and task.status in ["OP", "LO"]:
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   162
        task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO"
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   163
    if subs and task.status in ["OP", "LO", "CM"]:
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   164
        task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO"
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   165
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   166
    task.save()
ca2486e29178 added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents: 54
diff changeset
   167
    return task
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   168
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   169
def updateTask(task, title=None, desc=None, credits=None, tags_field=None):
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   170
    """ update the property accordingly.
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   171
    while updating title, check for uniqueness of title.
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   172
    return None if any error. 
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
    
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   175
    if title:
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   176
        try:
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   177
            task.title = title
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   178
            task.save()
74
7dc764854867 fixed a bug.
nishanth
parents: 63
diff changeset
   179
        except Task.IntegrityError:
63
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   180
            return None
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   181
    if desc:task.desc = desc
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   182
    if credits:task.credits = credits
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   183
    if tags_field:task.tags_field = tags_field
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   184
    task.save()
1fc027bf99ee added events in task.py for adding subtask and dependencies
nishanth
parents: 55
diff changeset
   185
    return task
92
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   186
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   187
def removeTask(main_task, sub_task):
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   188
    """ get the corresponding map object and remove the sub_task.
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
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   191
    mapobj = Map.objects.get(main=main_task)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   192
    mapobj.subs.remove(sub_task)
c99f09bebe56 added the capability to remove subtasks/dependencies .
nishanth
parents: 90
diff changeset
   193
    mapobj.save()
94
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   194
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   195
def removeUser(main_task, rem_user):
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   196
    """ 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
   197
    """
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   198
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   199
    main_task.assigned_users.remove(rem_user)
d1f59bbc2685 added capability to remove an assigned user.
nishanth
parents: 92
diff changeset
   200
    main_task.save()
95
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   201
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   202
def completeTask(main_task):
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   203
    """ set the status of task to CP.
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   204
    """
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   205
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   206
    main_task.status = "CP"
e4034904f82e added the event completeTask.
nishanth
parents: 94
diff changeset
   207
    main_task.save()
96
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   208
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   209
def assignCredits(task, given_by, given_to, points):
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   210
    """ make a proper request object.
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   211
    """
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   212
    
99
64c34c1f441f assign_credits event now creates a proper request object .
nishanth
parents: 96
diff changeset
   213
    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
   214
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   215
def addCredits(task, given_by, given_to, points):
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   216
    """ add credit to the credits model.
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   217
    """
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   218
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   219
    creditobj = Credit()
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   220
    creditobj.task = task
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   221
    creditobj.given_by = given_by
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   222
    creditobj.given_to = given_to
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   223
    creditobj.points = points
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   224
    creditobj.given_time = datetime.now()
2881ed1c52b0 added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents: 95
diff changeset
   225
    creditobj.save()