1 from datetime import datetime |
1 from datetime import datetime |
2 from pytask.taskapp.events.task import addCredits, addMentor |
2 from pytask.taskapp.events.task import addCredits, addMentor |
3 from pytask.taskapp.events.user import changeRole |
3 from pytask.taskapp.events.user import changeRole |
|
4 from pytask.taskapp.utilities.notification import create_notification |
4 |
5 |
5 def reply_to_request(request_obj, reply, replied_by): |
6 def reply_to_request(request_obj, reply, replied_by): |
6 """ |
7 """ |
7 makes a request replied with the given reply. |
8 makes a request replied with the given reply. |
8 arguments: |
9 arguments: |
16 request_obj.reply_date = datetime.now() |
17 request_obj.reply_date = datetime.now() |
17 request_obj.replied_by = replied_by |
18 request_obj.replied_by = replied_by |
18 request_obj.save() |
19 request_obj.save() |
19 |
20 |
20 if request_obj.role == "PY": |
21 if request_obj.role == "PY": |
21 if reply: |
22 ## note that we are not doing any check. we make requests invalid when an event like closing task happens. |
22 ## note that we are not checking if he is stilla mentor |
23 task = request_obj.task |
23 ## since we are not allowing removing mentors |
24 pynts = request_obj.pynts |
24 ## if we allow, we have complications like removing unreplied requests made by this mentor and stuff. |
25 receiving_user = request_obj.receiving_user |
25 ## but we check if this user is still an admin and put a notification if that you are no longer an admin and hence cannot do this. |
26 requested_by = request_obj.sent_by |
26 addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts) |
27 for a_mentor in task.mentors.all(): |
27 print "send yes notifications appropriately" |
28 if reply: |
28 else: |
29 addCredits(task, request_obj.sent_by, request_obj.receiving_user, pynts) |
29 print "send a no notificvaton" |
30 print "send yes notifications appropriately" |
|
31 #def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remark=None, receiving_user=None, pynts=None, requested_by): |
|
32 create_notification("PY", a_mentor, replied_by, True, task, receiving_user, pynts, requested_by) |
|
33 else: |
|
34 print "send a no notificvaton" |
|
35 create_notification("PY", a_mentor, replied_by, False, task, receiving_user, pynts, requested_by, request_obj.remarks) |
|
36 |
30 elif request_obj.role == "MT": |
37 elif request_obj.role == "MT": |
31 ## add him as a mentor to the task |
38 ## add him as a mentor to the task |
32 if reply: |
39 if reply: |
33 ## check for the current rights of request_obj.sent_by |
40 ## check for the current rights of request_obj.sent_by |
34 ## what if he is no more a mentor to the task |
41 ## what if he is no more a mentor to the task |