5 """ |
5 """ |
6 creates an unreplied request, based on the passed arguments |
6 creates an unreplied request, based on the passed arguments |
7 to - a list of users to which the notification is to be sent |
7 to - a list of users to which the notification is to be sent |
8 by - sender of request |
8 by - sender of request |
9 role - a two character field which represents the role requested |
9 role - a two character field which represents the role requested |
10 task - a requesting task (useful for sending admins a request to give Pynts to the user, assigning a user to a task) |
10 task - a requesting task (useful for sending admins a request to give Pynts to the user) |
11 assigned_user - user to whom the Pynts/Task is assigned to(useful for sending admins a request to give Pynts to the user, assigning a user to a task) |
11 assigned_user - user to whom the Pynts/Task is assigned to(useful for sending admins a request to give Pynts to the user) |
12 """ |
12 """ |
13 req = Request(creation_date=datetime.now()) |
13 req = Request(creation_date=datetime.now()) |
14 req.by = by |
14 req.by = by |
15 req.reply_date = datetime(1970,01,01) |
15 req.reply_date = datetime(1970,01,01) |
16 req.save() |
16 req.save() |
17 req.to = to |
17 req.to = to |
18 req.role = role |
18 req.role = role |
19 if task not None: |
19 if task is not None: |
20 req.task = task |
20 req.task = task |
21 if assigned_user not None: |
21 if assigned_user is not None: |
22 req.assigned_user = assigned_user |
22 req.assigned_user = assigned_user |
23 req.save() |
23 req.save() |
|
24 |
|
25 def reply_to_request(request_id, reply): |
|
26 """ |
|
27 makes a request replied with the given reply. |
|
28 arguments: |
|
29 request_id - a number denoting the id of the Request object |
|
30 reply - a boolean value to be given as reply (True/False) |
|
31 """ |
|
32 try: |
|
33 request = Request.objects.get(id = request_id) |
|
34 except Request.DoesNotExist: |
|
35 return False #No such request exist |
|
36 if request.replied is not True: |
|
37 request.reply = reply |
|
38 request.replied = True |
|
39 request.read = True |
|
40 request.reply_date = datetime.now() |
|
41 request.save() |
|
42 return True #Reply has been added successfully |
|
43 return False #Already replied |