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 |
4 |
4 def reply_to_request(request_obj, reply, replied_by): |
5 def reply_to_request(request_obj, reply, replied_by): |
5 """ |
6 """ |
6 makes a request replied with the given reply. |
7 makes a request replied with the given reply. |
7 arguments: |
8 arguments: |
16 request_obj.replied_by = replied_by |
17 request_obj.replied_by = replied_by |
17 request_obj.save() |
18 request_obj.save() |
18 |
19 |
19 if request_obj.role == "PY": |
20 if request_obj.role == "PY": |
20 if reply: |
21 if reply: |
|
22 ## note that we are not checking if he is stilla mentor |
|
23 ## since we are not allowing removing mentors |
|
24 ## if we allow, we have complications like removing unreplied requests made by this mentor and stuff. |
|
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. |
21 addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts) |
26 addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts) |
22 print "send yes notifications appropriately" |
27 print "send yes notifications appropriately" |
23 else: |
28 else: |
24 print "send a no notificvaton" |
29 print "send a no notificvaton" |
25 elif request_obj.role == "MT": |
30 elif request_obj.role == "MT": |
26 ## add him as a mentor to the task |
31 ## add him as a mentor to the task |
27 if reply: |
32 if reply: |
|
33 ## check for the current rights of request_obj.sent_by |
|
34 ## what if he is no more a mentor to the task |
28 addMentor(request_obj.task, request_obj.replied_by) |
35 addMentor(request_obj.task, request_obj.replied_by) |
29 ## pass on notification of request_obj.sent_by |
36 ## pass on notification of request_obj.sent_by |
30 else: |
37 else: |
31 print "request for mentor rejected" |
38 print "request for mentor rejected" |
32 ## pass on notification to request_obj.sent_by |
39 ## pass on notification to request_obj.sent_by |
33 |
40 |
34 elif request_obj.role in ["AD", "MG", "DV"]: |
41 elif request_obj.role in ["AD", "MG", "DV"]: |
35 if reply: |
42 if reply: |
36 pass |
|
37 ## make him the role |
43 ## make him the role |
38 ## changeRole(role=request_obj.role, made_by=request_obj.sent_by) |
44 ## here we check for rights just in case to be fine with demoted users. we change only the user who made request has that rights. |
|
45 changeRole(role=request_obj.role, user=request_obj.replied_by) |
39 else: |
46 else: |
40 ## notify request_obj.sent_by that it has been rejected |
47 ## notify request_obj.sent_by that it has been rejected |
41 pass |
48 pass |
42 return True #Reply has been added successfully |
49 return True #Reply has been added successfully |
43 return False #Already replied |
50 return False #Already replied |