author | nishanth |
Thu, 25 Feb 2010 02:11:49 +0530 | |
changeset 89 | 1cc03941ed5d |
parent 74 | 7dc764854867 |
child 90 | b2426897ff18 |
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. |
|
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
18 |
sub task can be added only if a task is in UP/OP/LO state. |
54 | 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. |
|
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
74
diff
changeset
|
35 |
note that deps can be added only if task is in UP/OP/LO state. |
54 | 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 |
||
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
73 |
def addClaim(task, message, user): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
74 |
""" 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
|
75 |
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
|
76 |
""" |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
77 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
78 |
task.claimed_users.add(user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
79 |
task.save() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
80 |
claim = Claim() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
81 |
claim.message = message |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
82 |
claim.task = task |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
83 |
claim.user = user |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
84 |
claim.creation_datetime = datetime.now() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
85 |
claim.save() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
86 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
87 |
def assignTask(task, user): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
88 |
""" 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
|
89 |
|
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
90 |
if task.status in ['OP', 'WR']: |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
91 |
task.assigned_users.add(user) |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
92 |
task.claimed_users.remove(user) |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
93 |
task.status = "WR" |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
94 |
task.save() |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
95 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
96 |
def getTask(tid): |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
97 |
""" 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
|
98 |
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
|
99 |
""" |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
100 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
|
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
110 |
task.save() |
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
111 |
return task |
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
112 |
|
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
113 |
def updateTask(task, title=None, desc=None, credits=None, tags_field=None): |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
114 |
""" update the property accordingly. |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
115 |
while updating title, check for uniqueness of title. |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
116 |
return None if any error. |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
117 |
""" |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
118 |
|
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
119 |
if title: |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
120 |
try: |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
121 |
task.title = title |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
122 |
task.save() |
74 | 123 |
except Task.IntegrityError: |
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
124 |
return None |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
125 |
if desc:task.desc = desc |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
126 |
if credits:task.credits = credits |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
127 |
if tags_field:task.tags_field = tags_field |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
128 |
task.save() |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
129 |
return task |