author | nishanth |
Fri, 26 Feb 2010 14:35:32 +0530 | |
changeset 115 | 52f2b9968ccd |
parent 107 | 4903b4973fc8 |
child 129 | e747da8bc110 |
permissions | -rw-r--r-- |
100 | 1 |
from datetime import datetime |
105
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
2 |
from pytask.taskapp.events.task import addCredits, addMentor |
107 | 3 |
from pytask.taskapp.events.user import changeRole |
100 | 4 |
|
5 |
def reply_to_request(request_obj, reply, replied_by): |
|
6 |
""" |
|
7 |
makes a request replied with the given reply. |
|
8 |
arguments: |
|
9 |
request_obj - Request object for which change is intended |
|
10 |
reply - a boolean value to be given as reply (True/False) |
|
11 |
replied_by - the user object who replies to the request |
|
12 |
""" |
|
13 |
if not request_obj.is_replied: |
|
14 |
request_obj.reply = reply |
|
15 |
request_obj.is_replied = True |
|
16 |
request_obj.reply_date = datetime.now() |
|
17 |
request_obj.replied_by = replied_by |
|
18 |
request_obj.save() |
|
19 |
||
20 |
if request_obj.role == "PY": |
|
21 |
if reply: |
|
107 | 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. |
|
100 | 26 |
addCredits(request_obj.task, request_obj.sent_by, request_obj.receiving_user, request_obj.pynts) |
27 |
print "send yes notifications appropriately" |
|
28 |
else: |
|
29 |
print "send a no notificvaton" |
|
30 |
elif request_obj.role == "MT": |
|
31 |
## add him as a mentor to the task |
|
105
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
32 |
if reply: |
107 | 33 |
## check for the current rights of request_obj.sent_by |
34 |
## what if he is no more a mentor to the task |
|
105
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
35 |
addMentor(request_obj.task, request_obj.replied_by) |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
36 |
## pass on notification of request_obj.sent_by |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
37 |
else: |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
38 |
print "request for mentor rejected" |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
39 |
## pass on notification to request_obj.sent_by |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
40 |
|
100 | 41 |
elif request_obj.role in ["AD", "MG", "DV"]: |
42 |
if reply: |
|
43 |
## make him the role |
|
107 | 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) |
|
100 | 46 |
else: |
47 |
## notify request_obj.sent_by that it has been rejected |
|
48 |
pass |
|
49 |
return True #Reply has been added successfully |
|
50 |
return False #Already replied |