author | nishanth |
Fri, 26 Feb 2010 18:34:30 +0530 | |
changeset 123 | a6b4234388c8 |
parent 122 | daee11bdfbaa |
child 132 | ca88bf4ad362 |
permissions | -rw-r--r-- |
58 | 1 |
from datetime import datetime |
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
2 |
|
87 | 3 |
from django.contrib.auth.models import User |
100
2275886511df
now admin can accept a request for assigning credits.
nishanth
parents:
99
diff
changeset
|
4 |
from pytask.taskapp.models import Request, Profile |
58 | 5 |
|
87 | 6 |
def create_request(sent_by,role,sent_to=None,task=None,receiving_user=None,pynts=0): |
58 | 7 |
""" |
8 |
creates an unreplied request, based on the passed arguments |
|
87 | 9 |
sent_to - a list of users to which the notification is to be sent |
10 |
sent_by - sender of request |
|
11 |
role - a two character field which represents the role requested, if role = 'PY' then sent to all admins |
|
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
71
diff
changeset
|
12 |
task - a requesting task (useful for sending admins a request to give Pynts to the user) |
87 | 13 |
receiving_user - user to whom the Pynts is assigned to(useful for sending admins a request to give Pynts to the user) |
14 |
pynts - the pynts assigned to the receiving user |
|
58 | 15 |
""" |
16 |
req = Request(creation_date=datetime.now()) |
|
87 | 17 |
req.sent_by = sent_by |
58 | 18 |
req.reply_date = datetime(1970,01,01) |
19 |
req.role = role |
|
87 | 20 |
req.pynts = pynts |
80 | 21 |
if task: |
71
801cf8fca53a
made change to the request model and corresponding create_request utility.
anoop
parents:
58
diff
changeset
|
22 |
req.task = task |
87 | 23 |
req.save() |
24 |
if role == 'PY': |
|
25 |
admin_profiles = Profile.objects.filter(rights='AD') |
|
99
64c34c1f441f
assign_credits event now creates a proper request object .
nishanth
parents:
87
diff
changeset
|
26 |
for admin_profile in admin_profiles: |
87 | 27 |
req.sent_to.add(admin_profile.user) |
28 |
req.receiving_user = receiving_user |
|
29 |
else: |
|
30 |
req.sent_to.add(sent_to) |
|
58 | 31 |
req.save() |
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
71
diff
changeset
|
32 |
|
122
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
33 |
def get_request(rid, user): |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
34 |
""" see if the request is replied or if he can not view the request, |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
35 |
raise 404 error. else return request. |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
36 |
""" |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
37 |
|
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
38 |
try: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
39 |
request_obj = Request.objects.get(id=rid) |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
40 |
except Request.DoesNotExist: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
41 |
return None |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
42 |
|
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
43 |
if request_obj.is_replied == True: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
44 |
return None |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
45 |
else: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
46 |
try: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
47 |
request_obj.sent_to.get(id=user.id) |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
48 |
except User.DoesNotExist: |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
49 |
return None |
daee11bdfbaa
now rid is not the position argument. it is request id.
nishanth
parents:
100
diff
changeset
|
50 |
return request_obj |