author | nishanth |
Tue, 02 Mar 2010 14:46:05 +0530 | |
changeset 174 | d034cd77cfa6 |
parent 167 | b61e45074ba1 |
child 189 | 8f5fb15ffd9b |
permissions | -rw-r--r-- |
19 | 1 |
from datetime import datetime |
153 | 2 |
from pytask.taskapp.models import Profile, Task, Comment, Claim, Map |
120 | 3 |
from pytask.taskapp.utilities.task import getTask |
99
64c34c1f441f
assign_credits event now creates a proper request object .
nishanth
parents:
96
diff
changeset
|
4 |
from pytask.taskapp.utilities.request import create_request |
119 | 5 |
from pytask.taskapp.utilities.helper import get_key |
131
85276c5aee5c
added notifications for approval and rejection of a mentor.
nishanth
parents:
126
diff
changeset
|
6 |
from pytask.taskapp.utilities.notification import create_notification |
19 | 7 |
|
113
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
8 |
def publishTask(task, rem_mentors=True, rem_comments=True): |
19 | 9 |
""" set the task status to open """ |
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
10 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
11 |
if task.sub_type == 'D': |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
12 |
deps, subs = task.map_subs.all(), [] |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
13 |
else: |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
14 |
subs, deps = task.map_subs.all(), [] |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
15 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
16 |
if subs or any(map(lambda t:t.status!="CM",deps)): |
53 | 17 |
task.status = "LO" |
18 |
else: |
|
19 |
task.status = "OP" |
|
111 | 20 |
|
113
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
21 |
if rem_mentors: |
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
22 |
task.mentors.clear() |
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
23 |
task.mentors.add(task.created_by) |
112
eadff01e395e
now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents:
111
diff
changeset
|
24 |
|
113
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
25 |
if rem_comments: |
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
26 |
task.comment_set.update(is_deleted=True) |
ea962d5fe99e
added option of specifying if previous mentors and comments must be removed in publish task event.
nishanth
parents:
112
diff
changeset
|
27 |
task.comment_set.update(deleted_by=task.created_by) |
112
eadff01e395e
now task page displays only undeleted comments. and publish task removes previous comments.
nishanth
parents:
111
diff
changeset
|
28 |
|
125 | 29 |
task.published_datetime = datetime.now() |
156 | 30 |
task.save() |
124
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
31 |
|
156 | 32 |
pending_requests = task.request_task.filter(is_valid=True, is_replied=False) |
33 |
pending_requests.update(is_valid=False) |
|
34 |
||
19 | 35 |
return task |
36 |
||
54 | 37 |
def addSubTask(main_task, sub_task): |
38 |
""" 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
|
39 |
sub task can be added only if a task is in UP/OP/LO state. |
54 | 40 |
""" |
41 |
||
42 |
## Shall modify after talking to pr about subtasks |
|
43 |
## I think i might even remove the concept of subtasks |
|
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
44 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
45 |
main_task.sub_type = "S" |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
46 |
main_task.save() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
47 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
48 |
try: |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
49 |
mapobj = Map.objects.get(main=main_task) |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
50 |
except Map.DoesNotExist: |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
51 |
mapobj = Map() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
52 |
mapobj.main = main_task |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
53 |
mapobj.save() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
54 |
mapobj.subs.add(sub_task) |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
55 |
mapobj.save() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
56 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
57 |
sub_tasks = getTask(main_task.id).subs |
54 | 58 |
if main_task.status == "OP": |
59 |
if any(map(lambda t:t.status!="CM",sub_tasks)): |
|
60 |
main_task.status = "LO" |
|
61 |
else: |
|
62 |
"CM" |
|
63 |
main_task.save() |
|
64 |
||
65 |
def addDep(main_task, dependency): |
|
66 |
""" add the dependency task to deps attribute of the task. |
|
67 |
update the status of main_task accordingly. |
|
89
1cc03941ed5d
added the capability of adding subtasks/dependencies .
nishanth
parents:
74
diff
changeset
|
68 |
note that deps can be added only if task is in UP/OP/LO state. |
54 | 69 |
And also if the task doesn't have any subs. |
70 |
""" |
|
71 |
||
90
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
72 |
main_task.sub_type = "D" |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
73 |
main_task.save() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
74 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
75 |
try: |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
76 |
mapobj = Map.objects.get(main=main_task) |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
77 |
except Map.DoesNotExist: |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
78 |
mapobj = Map() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
79 |
mapobj.main = main_task |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
80 |
mapobj.save() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
81 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
82 |
mapobj.subs.add(dependency) |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
83 |
mapobj.save() |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
84 |
|
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
85 |
deps = getTask(main_task.id).deps |
b2426897ff18
our task model does not meet out needs. so modified it and added a model called map. made the changes in views accordingly.phew!!!. this one took the hell out of me :( .
nishanth
parents:
89
diff
changeset
|
86 |
|
54 | 87 |
if main_task.status in ["OP", "LO"]: |
88 |
if all(map(lambda t:t.status=="CM",deps)): |
|
89 |
main_task.status = "OP" |
|
90 |
else: |
|
91 |
main_task.status = "LO" |
|
92 |
||
93 |
main_task.save() |
|
94 |
||
105
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
99
diff
changeset
|
95 |
def reqMentor(task, mentor, req_by): |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
99
diff
changeset
|
96 |
""" create a request object with role as MT. |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
99
diff
changeset
|
97 |
""" |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
99
diff
changeset
|
98 |
|
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
99
diff
changeset
|
99 |
create_request(sent_by=req_by, role="MT", sent_to=mentor, task=task) |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
99
diff
changeset
|
100 |
|
19 | 101 |
def addMentor(task,mentor): |
102 |
""" add the mentor to mentors list of the task """ |
|
103 |
||
104 |
task.mentors.add(mentor) |
|
105 |
task.save() |
|
119 | 106 |
return task |
107 |
||
19 | 108 |
def createTask(title,desc,created_by,credits): |
109 |
""" creates a bare minimum task with title, description and credits. |
|
110 |
the creator of the task will be assigned as a mentor for the task. |
|
111 |
""" |
|
112 |
||
119 | 113 |
while True: |
114 |
id = get_key() |
|
115 |
try: |
|
116 |
task = Task.objects.get(id__iexact=id) |
|
117 |
continue |
|
118 |
except Task.DoesNotExist: |
|
119 |
break |
|
120 |
||
19 | 121 |
try: |
166 | 122 |
task = Task.objects.exclude(status="DL").get(title__iexact=title) |
19 | 123 |
return None |
119 | 124 |
except: |
19 | 125 |
task = Task(title=title) |
119 | 126 |
|
127 |
task.id = id |
|
19 | 128 |
task.desc = desc |
129 |
task.created_by = created_by |
|
130 |
task.credits = credits |
|
131 |
task.creation_datetime = datetime.now() |
|
124
6d92b7cd2a37
taking care if publish task post request is made again. added published_date field to task.
nishanth
parents:
120
diff
changeset
|
132 |
task.published_datetime = datetime.now() |
19 | 133 |
task.save() |
134 |
return task |
|
135 |
||
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
136 |
def addClaim(task, message, user): |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
137 |
""" 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
|
138 |
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
|
139 |
""" |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
140 |
|
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
141 |
task.claimed_users.add(user) |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
142 |
task.save() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
143 |
claim = Claim() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
144 |
claim.message = message |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
145 |
claim.task = task |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
146 |
claim.user = user |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
147 |
claim.creation_datetime = datetime.now() |
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
148 |
claim.save() |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
149 |
|
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
150 |
user.request_sent_to.filter(is_replied=False, is_valid=True, role="MT", task=task).update(is_valid=False) |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
151 |
|
162 | 152 |
def assignTask(task, added_user, assigned_by): |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
153 |
""" 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
|
154 |
|
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
155 |
if task.status in ['OP', 'WR']: |
162 | 156 |
task.assigned_users.add(added_user) |
157 |
task.claimed_users.remove(added_user) |
|
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
158 |
task.status = "WR" |
25
c0e4fc8b8b5b
added the functionality to assign a task to one of the claimed users.
nishanth
parents:
21
diff
changeset
|
159 |
task.save() |
55
ca2486e29178
added a utility called getTask in task events and made changes in task views accordingly
nishanth
parents:
54
diff
changeset
|
160 |
|
162 | 161 |
create_notification("AU", added_user, assigned_by, task=task) |
162 |
||
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
163 |
|
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
164 |
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
|
165 |
""" update the property accordingly. |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
166 |
while updating title, check for uniqueness of title. |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
167 |
return None if any error. |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
168 |
""" |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
169 |
|
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
170 |
if title: |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
171 |
try: |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
172 |
task.title = title |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
173 |
task.save() |
74 | 174 |
except Task.IntegrityError: |
63
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
175 |
return None |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
176 |
if desc:task.desc = desc |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
177 |
if credits:task.credits = credits |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
178 |
if tags_field:task.tags_field = tags_field |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
179 |
task.save() |
1fc027bf99ee
added events in task.py for adding subtask and dependencies
nishanth
parents:
55
diff
changeset
|
180 |
return task |
92
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
181 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
182 |
def removeTask(main_task, sub_task): |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
183 |
""" get the corresponding map object and remove the sub_task. |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
184 |
""" |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
185 |
|
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
186 |
mapobj = Map.objects.get(main=main_task) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
187 |
mapobj.subs.remove(sub_task) |
c99f09bebe56
added the capability to remove subtasks/dependencies .
nishanth
parents:
90
diff
changeset
|
188 |
mapobj.save() |
94 | 189 |
|
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
190 |
def removeUser(main_task, rem_user, removed_by, reason=None): |
94 | 191 |
""" right now, just remove the user from the list of assigned_users. |
192 |
""" |
|
193 |
||
194 |
main_task.assigned_users.remove(rem_user) |
|
195 |
main_task.save() |
|
95 | 196 |
|
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
197 |
## TODiscuss : when a user is kicked off, his pending requests for pynts is made invalid |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
198 |
rem_user.request_receiving_user.filter(task=main_task,role="PY",is_valid=True,is_replied=False).update(is_valid=False) |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
199 |
|
162 | 200 |
create_notification("RU", rem_user, removed_by, task=main_task, remarks=reason) |
158
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
201 |
## TODO : create notification to the victim |
c43e0114e593
removing user deletes all the pending requests that request giving him pynts.
nishanth
parents:
156
diff
changeset
|
202 |
|
96
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
95
diff
changeset
|
203 |
def assignCredits(task, given_by, given_to, points): |
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
95
diff
changeset
|
204 |
""" make a proper request object. |
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
95
diff
changeset
|
205 |
""" |
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
95
diff
changeset
|
206 |
|
99
64c34c1f441f
assign_credits event now creates a proper request object .
nishanth
parents:
96
diff
changeset
|
207 |
create_request(sent_by=given_by, role="PY", task=task, receiving_user=given_to, pynts=points ) |
96
2881ed1c52b0
added events addCredits and assignCredits and modified assign_credits view accordingly.
nishanth
parents:
95
diff
changeset
|
208 |
|
114 | 209 |
def completeTask(task, marked_by): |
210 |
""" set the status of task as completed. |
|
211 |
We dont have to inform parent tasks. |
|
212 |
That part is taken care by getTask method. |
|
213 |
""" |
|
214 |
||
215 |
task.status = "CM" |
|
216 |
task.save() |
|
217 |
||
126 | 218 |
pending_requests = task.request_task.filter(is_replied=False) |
219 |
pending_requests.update(is_valid=False) |
|
117
58fa1d626d37
now if a task is closed/completed all its pending requests will be made invalid.
nishanth
parents:
114
diff
changeset
|
220 |
|
114 | 221 |
## generate notification appropriately using marked_by |
222 |
## we also have to mark unread requests as invalid |
|
223 |
||
153 | 224 |
for a_user in task.assigned_users.all(): |
225 |
create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task) |
|
226 |
||
227 |
for a_user in task.claimed_users.all(): |
|
228 |
create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task) |
|
229 |
||
230 |
for a_mentor in task.mentors.all(): |
|
231 |
create_notification(role="CM", sent_to=a_mentor, sent_from=marked_by, task=task) |
|
232 |
||
233 |
def closeTask(task, closed_by, reason=None): |
|
126 | 234 |
""" set the status of task as CD. |
235 |
generate notifications accordingly. |
|
236 |
""" |
|
114 | 237 |
|
126 | 238 |
task.status = "CD" |
239 |
task.save() |
|
240 |
||
241 |
pending_requests = task.request_task.filter(is_replied=False) |
|
242 |
pending_requests.update(is_valid=False) |
|
243 |
||
244 |
## generate notifications here |
|
245 |
||
153 | 246 |
for a_user in task.assigned_users.all(): |
156 | 247 |
create_notification(role="CD", sent_to=a_user, sent_from=closed_by, task=task, remarks=reason) |
126 | 248 |
|
153 | 249 |
for a_user in task.claimed_users.all(): |
156 | 250 |
create_notification(role="CD", sent_to=a_user, sent_from=closed_by, task=task, remarks=reason) |
153 | 251 |
|
252 |
for a_mentor in task.mentors.all(): |
|
156 | 253 |
create_notification(role="CD", sent_to=a_mentor, sent_from=closed_by, task=task, remarks=reason) |
153 | 254 |
|
167 | 255 |
def deleteTask(task, deleted_by, reason=None): |
256 |
""" set the task status as DL |
|
257 |
notify all its other viewers about the deleting of task. |
|
258 |
""" |
|
153 | 259 |
|
167 | 260 |
task.status = "DL" |
261 |
task.save() |
|
262 |
||
263 |
pending_requests = task.request_task.filter(is_replied=False,is_valid=True) |
|
264 |
pending_requests.update(is_valid=False) |
|
265 |
||
266 |
for a_mentor in task.mentors.exclude(id=deleted_by.id): |
|
267 |
create_notification("DL", sent_to=a_mentor, sent_from=deleted_by, task=task, remarks=reason) |