author | nishanth |
Tue, 23 Feb 2010 12:16:28 +0530 | |
changeset 55 | ca2486e29178 |
parent 54 | 943d682aefdd |
child 63 | 1fc027bf99ee |
permissions | -rw-r--r-- |
19 | 1 |
from datetime import datetime |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
2 |
from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim |
19 | 3 |
|
4 |
def publishTask(task): |
|
5 |
""" set the task status to open """ |
|
6 |
||
53 | 7 |
sub_tasks = task.subs.all() |
8 |
dependencies = task.deps.all() |
|
9 |
if sub_tasks or any(map(lambda t:t.status!="CM",dependencies)): |
|
10 |
task.status = "LO" |
|
11 |
else: |
|
12 |
task.status = "OP" |
|
19 | 13 |
task.save() |
14 |
return task |
|
15 |
||
54 | 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() |
|
48 |
||
19 | 49 |
def addMentor(task,mentor): |
50 |
""" add the mentor to mentors list of the task """ |
|
51 |
||
52 |
task.mentors.add(mentor) |
|
53 |
task.save() |
|
54 |
return task |
|
55 |
||
56 |
def createTask(title,desc,created_by,credits): |
|
57 |
""" creates a bare minimum task with title, description and credits. |
|
58 |
the creator of the task will be assigned as a mentor for the task. |
|
59 |
""" |
|
60 |
||
61 |
try: |
|
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
62 |
task = Task.objects.get(title__iexact=title) |
19 | 63 |
return None |
64 |
except Task.DoesNotExist: |
|
65 |
task = Task(title=title) |
|
66 |
task.desc = desc |
|
67 |
task.created_by = created_by |
|
68 |
task.credits = credits |
|
69 |
task.creation_datetime = datetime.now() |
|
70 |
task.save() |
|
71 |
return task |
|
72 |
||
21
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
73 |
def addSubTask(main_task, sub_task): |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
74 |
""" add sub_task to subs list of main_task """ |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
75 |
|
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
76 |
main_task.subs.add(sub_task) |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
77 |
main_task.status = "LO" |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
78 |
main_task.save() |
c28774fe7ffd
implemented "add another mentor" functionality to a task.
nishanth
parents:
19
diff
changeset
|
79 |
return main_task |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
80 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
81 |
def addClaim(task, message, user): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
82 |
""" add claim data to the database if it does not exist |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
83 |
and also update the claimed users field of the task. |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
84 |
""" |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
85 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
86 |
task.claimed_users.add(user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
87 |
task.status = "CL" |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
88 |
task.save() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
89 |
claim = Claim() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
90 |
claim.message = message |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
91 |
claim.task = task |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
92 |
claim.user = user |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
93 |
claim.creation_datetime = datetime.now() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
94 |
claim.save() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
95 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
96 |
def assignTask(task, user): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
97 |
""" check for the status of task and assign it to the particular user """ |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
98 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
99 |
task.assigned_users.add(user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
100 |
task.status = "AS" |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
101 |
task.save() |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
102 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
103 |
def getTask(tid): |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
104 |
""" retreive the task from database. |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
105 |
if the task has deps or subs, update its status correspondingly. |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
106 |
""" |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
107 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
108 |
task = Task.objects.get(id=tid) |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
109 |
deps = task.deps.all() |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
110 |
subs = task.subs.all() |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
111 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
112 |
if deps and task.status in ["OP", "LO"]: |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
113 |
task.status = "OP" if all(map(lambda t:t.status=="CM",deps)) else "LO" |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
114 |
if subs and task.status in ["OP", "LO", "CM"]: |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
115 |
task.status = "CM" if all(map(lambda t:t.status=="CM",subs)) else "LO" |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
116 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
117 |
task.save() |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
118 |
return task |