taskapp/events/task.py
changeset 54 943d682aefdd
parent 53 2c5062a93734
child 55 ca2486e29178
equal deleted inserted replaced
53:2c5062a93734 54:943d682aefdd
    10         task.status = "LO"
    10         task.status = "LO"
    11     else:
    11     else:
    12         task.status = "OP"
    12         task.status = "OP"
    13     task.save()
    13     task.save()
    14     return task
    14     return task
       
    15 
       
    16 def addSubTask(main_task, sub_task):
       
    17     """ add the task to subs attribute of the task and update its status.
       
    18     sub task can be added only if a task is in UP/OP/LO/Cd state.
       
    19     """
       
    20 
       
    21     ## Shall modify after talking to pr about subtasks
       
    22     ## I think i might even remove the concept of subtasks
       
    23     main_task.subs.add(sub_task)
       
    24     sub_tasks = main_task.subs.all()
       
    25     if main_task.status == "OP":
       
    26         if any(map(lambda t:t.status!="CM",sub_tasks)):
       
    27             main_task.status = "LO"
       
    28         else:
       
    29             "CM"
       
    30     main_task.save()
       
    31 
       
    32 def addDep(main_task, dependency):
       
    33     """ add the dependency task to deps attribute of the task.
       
    34     update the status of main_task accordingly.
       
    35     note that deps can be added only if task is in UP/OP/LO/CD state.
       
    36     And also if the task doesn't have any subs.
       
    37     """
       
    38 
       
    39     main_task.deps.add(dependency)
       
    40     deps = main_task.deps.all()
       
    41     if main_task.status in ["OP", "LO"]: 
       
    42         if all(map(lambda t:t.status=="CM",deps)):
       
    43             main_task.status = "OP"
       
    44         else:
       
    45             main_task.status = "LO"
       
    46     
       
    47     main_task.save()
    15 
    48 
    16 def addMentor(task,mentor):
    49 def addMentor(task,mentor):
    17     """ add the mentor to mentors list of the task """
    50     """ add the mentor to mentors list of the task """
    18     
    51     
    19     task.mentors.add(mentor)
    52     task.mentors.add(mentor)