author | nishanth |
Sat, 27 Feb 2010 14:22:26 +0530 | |
changeset 129 | e747da8bc110 |
parent 107 | 4903b4973fc8 |
child 130 | 9417ae986d2a |
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 |
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
4 |
from pytask.taskapp.utilities.notification import create_notification |
100 | 5 |
|
6 |
def reply_to_request(request_obj, reply, replied_by): |
|
7 |
""" |
|
8 |
makes a request replied with the given reply. |
|
9 |
arguments: |
|
10 |
request_obj - Request object for which change is intended |
|
11 |
reply - a boolean value to be given as reply (True/False) |
|
12 |
replied_by - the user object who replies to the request |
|
13 |
""" |
|
14 |
if not request_obj.is_replied: |
|
15 |
request_obj.reply = reply |
|
16 |
request_obj.is_replied = True |
|
17 |
request_obj.reply_date = datetime.now() |
|
18 |
request_obj.replied_by = replied_by |
|
19 |
request_obj.save() |
|
20 |
||
21 |
if request_obj.role == "PY": |
|
129
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
22 |
## note that we are not doing any check. we make requests invalid when an event like closing task happens. |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
23 |
task = request_obj.task |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
24 |
pynts = request_obj.pynts |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
25 |
receiving_user = request_obj.receiving_user |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
26 |
requested_by = request_obj.sent_by |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
27 |
for a_mentor in task.mentors.all(): |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
28 |
if reply: |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
29 |
addCredits(task, request_obj.sent_by, request_obj.receiving_user, pynts) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
30 |
print "send yes notifications appropriately" |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
31 |
#def create_notification(role, sent_to, sent_from=None, reply=None, task=None, remark=None, receiving_user=None, pynts=None, requested_by): |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
32 |
create_notification("PY", a_mentor, replied_by, True, task, receiving_user, pynts, requested_by) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
33 |
else: |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
34 |
print "send a no notificvaton" |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
35 |
create_notification("PY", a_mentor, replied_by, False, task, receiving_user, pynts, requested_by, request_obj.remarks) |
e747da8bc110
notifications work for approving and rejecting credits.
nishanth
parents:
107
diff
changeset
|
36 |
|
100 | 37 |
elif request_obj.role == "MT": |
38 |
## 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
|
39 |
if reply: |
107 | 40 |
## check for the current rights of request_obj.sent_by |
41 |
## 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
|
42 |
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
|
43 |
## 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
|
44 |
else: |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
45 |
print "request for mentor rejected" |
091b044a3bf4
now adding mentor for a task happens through request. notifications still pending though
nishanth
parents:
100
diff
changeset
|
46 |
## 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
|
47 |
|
100 | 48 |
elif request_obj.role in ["AD", "MG", "DV"]: |
49 |
if reply: |
|
50 |
## make him the role |
|
107 | 51 |
## 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. |
52 |
changeRole(role=request_obj.role, user=request_obj.replied_by) |
|
100 | 53 |
else: |
54 |
## notify request_obj.sent_by that it has been rejected |
|
55 |
pass |
|
56 |
return True #Reply has been added successfully |
|
57 |
return False #Already replied |