taskapp/utilities/task.py
author anoop
Mon, 08 Mar 2010 16:30:35 +0530
changeset 209 f34052de27f5
parent 155 52958289d81f
permissions -rw-r--r--
email address displayed was incorrect, fixed it.
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"
155
52958289d81f now if a task has subs, it will remain locked forever.
nishanth
parents: 120
diff changeset
    30
52958289d81f now if a task has subs, it will remain locked forever.
nishanth
parents: 120
diff changeset
    31
    ## a task with subs will remain in "LO" and will be made "OP" only if all subs are removed.
52958289d81f now if a task has subs, it will remain locked forever.
nishanth
parents: 120
diff changeset
    32
    if subs and task.status in ["OP", "LO"]:
52958289d81f now if a task has subs, it will remain locked forever.
nishanth
parents: 120
diff changeset
    33
        task.status = "LO"
120
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    34
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    35
    task.save()
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    36
    return task
aad4e6065d85 moved the getTask method to task_utilities.
nishanth
parents:
diff changeset
    37