taskapp/events/task.py
author nishanth
Tue, 23 Feb 2010 11:52:22 +0530
changeset 54 943d682aefdd
parent 53 2c5062a93734
child 55 ca2486e29178
permissions -rw-r--r--
added the events addSubTask and addDep.
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
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
     2
from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     3
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     4
def publishTask(task):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     5
    """ set the task status to open """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
     6
    
53
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
     7
    sub_tasks = task.subs.all()
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
     8
    dependencies = task.deps.all()
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
     9
    if sub_tasks or any(map(lambda t:t.status!="CM",dependencies)):
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    10
        task.status = "LO"
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    11
    else:
2c5062a93734 updated publishtask event .
nishanth
parents: 25
diff changeset
    12
        task.status = "OP"
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    13
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    14
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    15
54
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    16
def addSubTask(main_task, sub_task):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    17
    """ add the task to subs attribute of the task and update its status.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    18
    sub task can be added only if a task is in UP/OP/LO/Cd state.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    19
    """
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    20
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    21
    ## Shall modify after talking to pr about subtasks
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    22
    ## I think i might even remove the concept of subtasks
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    23
    main_task.subs.add(sub_task)
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    24
    sub_tasks = main_task.subs.all()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    25
    if main_task.status == "OP":
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    26
        if any(map(lambda t:t.status!="CM",sub_tasks)):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    27
            main_task.status = "LO"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    28
        else:
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    29
            "CM"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    30
    main_task.save()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    31
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    32
def addDep(main_task, dependency):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    33
    """ add the dependency task to deps attribute of the task.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    34
    update the status of main_task accordingly.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    35
    note that deps can be added only if task is in UP/OP/LO/CD state.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    36
    And also if the task doesn't have any subs.
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    37
    """
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    38
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    39
    main_task.deps.add(dependency)
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    40
    deps = main_task.deps.all()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    41
    if main_task.status in ["OP", "LO"]: 
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    42
        if all(map(lambda t:t.status=="CM",deps)):
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    43
            main_task.status = "OP"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    44
        else:
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    45
            main_task.status = "LO"
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    46
    
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    47
    main_task.save()
943d682aefdd added the events addSubTask and addDep.
nishanth
parents: 53
diff changeset
    48
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    49
def addMentor(task,mentor):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    50
    """ add the mentor to mentors list of the task """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    51
    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    52
    task.mentors.add(mentor)
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    53
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    54
    return task    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    55
    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    56
def createTask(title,desc,created_by,credits):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    57
    """ creates a bare minimum task with title, description and credits.
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    58
    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
    59
    """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    60
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    61
    try:
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    62
        task = Task.objects.get(title__iexact=title)
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    63
        return None
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    64
    except Task.DoesNotExist:
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    65
        task = Task(title=title)
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    66
    task.desc = desc
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    67
    task.created_by = created_by
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    68
    task.credits = credits
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    69
    task.creation_datetime = datetime.now()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    70
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    71
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    72
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    73
def addSubTask(main_task, sub_task):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    74
    """ add sub_task to subs list of main_task """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    75
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    76
    main_task.subs.add(sub_task)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    77
    main_task.status = "LO"
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    78
    main_task.save()
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    79
    return main_task
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    80
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    81
def addClaim(task, message, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    82
    """ 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
    83
    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
    84
    """
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    85
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    86
    task.claimed_users.add(user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    87
    task.status = "CL"
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    88
    task.save()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    89
    claim = Claim()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    90
    claim.message = message
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    91
    claim.task = task
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    92
    claim.user = user
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    93
    claim.creation_datetime = datetime.now()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    94
    claim.save()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    95
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    96
def assignTask(task, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    97
    """ 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
    98
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    99
    task.assigned_users.add(user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   100
    task.status = "AS"
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
   101
    task.save()