taskapp/utilities/task.py
author nishanth
Sun, 28 Feb 2010 01:15:15 +0530
changeset 133 34187a80d279
parent 120 aad4e6065d85
child 155 52958289d81f
permissions -rw-r--r--
added next and previous capabilities to requests and notifications.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
120
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     1
from django.http import Http404
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     2
from pytask.taskapp.models import Task, Map
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     3
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     4
def getTask(tid):
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     5
    """ retreive the task from database.
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     6
    if the task has deps or subs, update its status correspondingly.
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     7
    """
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     8
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
     9
    try:
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    10
        task = Task.objects.get(id=tid)
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    11
    except Task.DoesNotExist:
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    12
        raise Http404
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    13
    try:
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    14
        mapobj = Map.objects.get(main=task)
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    15
    except Map.DoesNotExist:
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    16
        mapobj = Map()
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    17
        mapobj.main = task
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    18
        mapobj.save()
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    19
        
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    20
    task_subs = mapobj.subs.all()
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    21
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    22
    if task.sub_type == "D":
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    23
        task.deps, task.subs = task_subs, []
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    24
    elif task.sub_type == "S":
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    25
        task.subs, task.deps = task_subs, []
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    26
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    27
    deps, subs = task.deps, task.subs
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    28
    if deps and task.status in ["OP", "LO"]:
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    29
        task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO"
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    30
    if subs and task.status in ["OP", "LO", "CM"]:
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    31
        task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO"
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    32
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    33
    task.save()
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    34
    return task
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    35