taskapp/events/task.py
author nishanth
Tue, 23 Feb 2010 10:41:43 +0530
changeset 53 2c5062a93734
parent 25 c0e4fc8b8b5b
child 54 943d682aefdd
permissions -rw-r--r--
updated publishtask 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
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
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    16
def addMentor(task,mentor):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    17
    """ add the mentor to mentors list of the task """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    18
    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    19
    task.mentors.add(mentor)
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    20
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    21
    return task    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    22
    
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    23
def createTask(title,desc,created_by,credits):
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    24
    """ creates a bare minimum task with title, description and credits.
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    25
    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
    26
    """
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    27
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    28
    try:
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    29
        task = Task.objects.get(title__iexact=title)
19
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    30
        return None
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    31
    except Task.DoesNotExist:
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    32
        task = Task(title=title)
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    33
    task.desc = desc
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    34
    task.created_by = created_by
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    35
    task.credits = credits
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    36
    task.creation_datetime = datetime.now()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    37
    task.save()
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    38
    return task
c52f7cde9861 added events/task.py and templates/error.html.
nishanth
parents:
diff changeset
    39
21
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    40
def addSubTask(main_task, sub_task):
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    41
    """ add sub_task to subs list of main_task """
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    42
    
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    43
    main_task.subs.add(sub_task)
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    44
    main_task.status = "LO"
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    45
    main_task.save()
c28774fe7ffd implemented "add another mentor" functionality to a task.
nishanth
parents: 19
diff changeset
    46
    return main_task
25
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    47
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    48
def addClaim(task, message, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    49
    """ 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
    50
    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
    51
    """
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    52
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    53
    task.claimed_users.add(user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    54
    task.status = "CL"
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    55
    task.save()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    56
    claim = Claim()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    57
    claim.message = message
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    58
    claim.task = task
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    59
    claim.user = user
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    60
    claim.creation_datetime = datetime.now()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    61
    claim.save()
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    62
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    63
def assignTask(task, user):
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    64
    """ 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
    65
    
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    66
    task.assigned_users.add(user)
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    67
    task.status = "AS"
c0e4fc8b8b5b added the functionality to assign a task to one of the claimed users.
nishanth
parents: 21
diff changeset
    68
    task.save()