taskapp/utilities/task.py
changeset 120 aad4e6065d85
child 155 52958289d81f
equal deleted inserted replaced
119:39ab7c460143 120:aad4e6065d85
       
     1 from django.http import Http404
       
     2 from pytask.taskapp.models import Task, Map
       
     3 
       
     4 def getTask(tid):
       
     5     """ retreive the task from database.
       
     6     if the task has deps or subs, update its status correspondingly.
       
     7     """
       
     8 
       
     9     try:
       
    10         task = Task.objects.get(id=tid)
       
    11     except Task.DoesNotExist:
       
    12         raise Http404
       
    13     try:
       
    14         mapobj = Map.objects.get(main=task)
       
    15     except Map.DoesNotExist:
       
    16         mapobj = Map()
       
    17         mapobj.main = task
       
    18         mapobj.save()
       
    19         
       
    20     task_subs = mapobj.subs.all()
       
    21 
       
    22     if task.sub_type == "D":
       
    23         task.deps, task.subs = task_subs, []
       
    24     elif task.sub_type == "S":
       
    25         task.subs, task.deps = task_subs, []
       
    26 
       
    27     deps, subs = task.deps, task.subs
       
    28     if deps and task.status in ["OP", "LO"]:
       
    29         task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO"
       
    30     if subs and task.status in ["OP", "LO", "CM"]:
       
    31         task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO"
       
    32 
       
    33     task.save()
       
    34     return task
       
    35