1 from datetime import datetime |
1 from datetime import datetime |
2 from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim, Map |
2 from pytask.taskapp.models import Profile, Task, Comment, Claim, Map |
3 from pytask.taskapp.utilities.task import getTask |
3 from pytask.taskapp.utilities.task import getTask |
4 from pytask.taskapp.utilities.request import create_request |
4 from pytask.taskapp.utilities.request import create_request |
5 from pytask.taskapp.utilities.helper import get_key |
5 from pytask.taskapp.utilities.helper import get_key |
6 from pytask.taskapp.utilities.notification import create_notification |
6 from pytask.taskapp.utilities.notification import create_notification |
7 |
7 |
100 |
100 |
101 task.mentors.add(mentor) |
101 task.mentors.add(mentor) |
102 task.save() |
102 task.save() |
103 return task |
103 return task |
104 |
104 |
105 |
|
106 |
|
107 def createTask(title,desc,created_by,credits): |
105 def createTask(title,desc,created_by,credits): |
108 """ creates a bare minimum task with title, description and credits. |
106 """ creates a bare minimum task with title, description and credits. |
109 the creator of the task will be assigned as a mentor for the task. |
107 the creator of the task will be assigned as a mentor for the task. |
110 """ |
108 """ |
111 |
109 |
187 """ |
185 """ |
188 |
186 |
189 main_task.assigned_users.remove(rem_user) |
187 main_task.assigned_users.remove(rem_user) |
190 main_task.save() |
188 main_task.save() |
191 |
189 |
192 def completeTask(main_task): |
|
193 """ set the status of task to CP. |
|
194 """ |
|
195 |
|
196 main_task.status = "CP" |
|
197 main_task.save() |
|
198 |
|
199 def assignCredits(task, given_by, given_to, points): |
190 def assignCredits(task, given_by, given_to, points): |
200 """ make a proper request object. |
191 """ make a proper request object. |
201 """ |
192 """ |
202 |
193 |
203 create_request(sent_by=given_by, role="PY", task=task, receiving_user=given_to, pynts=points ) |
194 create_request(sent_by=given_by, role="PY", task=task, receiving_user=given_to, pynts=points ) |
204 |
|
205 def addCredits(task, given_by, given_to, points): |
|
206 """ add credit to the credits model. |
|
207 """ |
|
208 |
|
209 creditobj = Credit() |
|
210 creditobj.task = task |
|
211 creditobj.given_by = given_by |
|
212 creditobj.given_to = given_to |
|
213 creditobj.points = points |
|
214 creditobj.given_time = datetime.now() |
|
215 creditobj.save() |
|
216 |
195 |
217 def completeTask(task, marked_by): |
196 def completeTask(task, marked_by): |
218 """ set the status of task as completed. |
197 """ set the status of task as completed. |
219 We dont have to inform parent tasks. |
198 We dont have to inform parent tasks. |
220 That part is taken care by getTask method. |
199 That part is taken care by getTask method. |
227 pending_requests.update(is_valid=False) |
206 pending_requests.update(is_valid=False) |
228 |
207 |
229 ## generate notification appropriately using marked_by |
208 ## generate notification appropriately using marked_by |
230 ## we also have to mark unread requests as invalid |
209 ## we also have to mark unread requests as invalid |
231 |
210 |
232 def closeTask(task, closed_by): |
211 for a_user in task.assigned_users.all(): |
|
212 create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task) |
|
213 |
|
214 for a_user in task.claimed_users.all(): |
|
215 create_notification(role="CM", sent_to=a_user, sent_from=marked_by, task=task) |
|
216 |
|
217 for a_mentor in task.mentors.all(): |
|
218 create_notification(role="CM", sent_to=a_mentor, sent_from=marked_by, task=task) |
|
219 |
|
220 |
|
221 |
|
222 def closeTask(task, closed_by, reason=None): |
233 """ set the status of task as CD. |
223 """ set the status of task as CD. |
234 generate notifications accordingly. |
224 generate notifications accordingly. |
235 """ |
225 """ |
236 |
226 |
237 task.status = "CD" |
227 task.status = "CD" |
240 pending_requests = task.request_task.filter(is_replied=False) |
230 pending_requests = task.request_task.filter(is_replied=False) |
241 pending_requests.update(is_valid=False) |
231 pending_requests.update(is_valid=False) |
242 |
232 |
243 ## generate notifications here |
233 ## generate notifications here |
244 |
234 |
245 |
235 for a_user in task.assigned_users.all(): |
|
236 create_notification(role="CD", sent_to=a_user, sent_from=marked_by, task=task) |
|
237 |
|
238 for a_user in task.claimed_users.all(): |
|
239 create_notification(role="CD", sent_to=a_user, sent_from=marked_by, task=task) |
|
240 |
|
241 for a_mentor in task.mentors.all(): |
|
242 create_notification(role="CD", sent_to=a_mentor, sent_from=marked_by, task=task) |
|
243 |
|
244 |