1 from datetime import datetime |
1 from datetime import datetime |
2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim |
2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map |
3 |
3 |
4 def publishTask(task): |
4 def publishTask(task): |
5 """ set the task status to open """ |
5 """ set the task status to open """ |
6 |
6 |
7 sub_tasks = task.subs.all() |
7 if task.sub_type == 'D': |
8 dependencies = task.deps.all() |
8 deps, subs = task.map_subs.all(), [] |
9 if sub_tasks or any(map(lambda t:t.status!="CM",dependencies)): |
9 else: |
|
10 subs, deps = task.map_subs.all(), [] |
|
11 |
|
12 if subs or any(map(lambda t:t.status!="CM",deps)): |
10 task.status = "LO" |
13 task.status = "LO" |
11 else: |
14 else: |
12 task.status = "OP" |
15 task.status = "OP" |
13 task.save() |
16 task.save() |
14 return task |
17 return task |
18 sub task can be added only if a task is in UP/OP/LO state. |
21 sub task can be added only if a task is in UP/OP/LO state. |
19 """ |
22 """ |
20 |
23 |
21 ## Shall modify after talking to pr about subtasks |
24 ## Shall modify after talking to pr about subtasks |
22 ## I think i might even remove the concept of subtasks |
25 ## I think i might even remove the concept of subtasks |
23 main_task.subs.add(sub_task) |
26 |
24 sub_tasks = main_task.subs.all() |
27 main_task.sub_type = "S" |
|
28 main_task.save() |
|
29 |
|
30 try: |
|
31 mapobj = Map.objects.get(main=main_task) |
|
32 except Map.DoesNotExist: |
|
33 mapobj = Map() |
|
34 mapobj.main = main_task |
|
35 mapobj.save() |
|
36 mapobj.subs.add(sub_task) |
|
37 mapobj.save() |
|
38 |
|
39 sub_tasks = getTask(main_task.id).subs |
25 if main_task.status == "OP": |
40 if main_task.status == "OP": |
26 if any(map(lambda t:t.status!="CM",sub_tasks)): |
41 if any(map(lambda t:t.status!="CM",sub_tasks)): |
27 main_task.status = "LO" |
42 main_task.status = "LO" |
28 else: |
43 else: |
29 "CM" |
44 "CM" |
34 update the status of main_task accordingly. |
49 update the status of main_task accordingly. |
35 note that deps can be added only if task is in UP/OP/LO state. |
50 note that deps can be added only if task is in UP/OP/LO state. |
36 And also if the task doesn't have any subs. |
51 And also if the task doesn't have any subs. |
37 """ |
52 """ |
38 |
53 |
39 main_task.deps.add(dependency) |
54 main_task.sub_type = "D" |
40 deps = main_task.deps.all() |
55 main_task.save() |
|
56 |
|
57 try: |
|
58 mapobj = Map.objects.get(main=main_task) |
|
59 except Map.DoesNotExist: |
|
60 mapobj = Map() |
|
61 mapobj.main = main_task |
|
62 mapobj.save() |
|
63 |
|
64 mapobj.subs.add(dependency) |
|
65 mapobj.save() |
|
66 |
|
67 deps = getTask(main_task.id).deps |
|
68 |
41 if main_task.status in ["OP", "LO"]: |
69 if main_task.status in ["OP", "LO"]: |
42 if all(map(lambda t:t.status=="CM",deps)): |
70 if all(map(lambda t:t.status=="CM",deps)): |
43 main_task.status = "OP" |
71 main_task.status = "OP" |
44 else: |
72 else: |
45 main_task.status = "LO" |
73 main_task.status = "LO" |
97 """ retreive the task from database. |
125 """ retreive the task from database. |
98 if the task has deps or subs, update its status correspondingly. |
126 if the task has deps or subs, update its status correspondingly. |
99 """ |
127 """ |
100 |
128 |
101 task = Task.objects.get(id=tid) |
129 task = Task.objects.get(id=tid) |
102 deps = task.deps.all() |
130 try: |
103 subs = task.subs.all() |
131 mapobj = Map.objects.get(main=task) |
|
132 except Map.DoesNotExist: |
|
133 mapobj = Map() |
|
134 mapobj.main = task |
|
135 mapobj.save() |
|
136 |
|
137 task_subs = mapobj.subs.all() |
104 |
138 |
|
139 if task.sub_type == "D": |
|
140 task.deps, task.subs = task_subs, [] |
|
141 elif task.sub_type == "S": |
|
142 task.subs, task.deps = task_subs, [] |
|
143 |
|
144 deps, subs = task.deps, task.subs |
105 if deps and task.status in ["OP", "LO"]: |
145 if deps and task.status in ["OP", "LO"]: |
106 task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO" |
146 task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO" |
107 if subs and task.status in ["OP", "LO", "CM"]: |
147 if subs and task.status in ["OP", "LO", "CM"]: |
108 task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO" |
148 task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO" |
109 |
149 |