author | nishanth |
Fri, 26 Feb 2010 23:22:23 +0530 | |
changeset 125 | d3cfceb8e120 |
parent 123 | a6b4234388c8 |
child 129 | e747da8bc110 |
permissions | -rw-r--r-- |
123 | 1 |
from datetime import datetime |
2 |
from django.contrib.auth.models import User |
|
57 | 3 |
from pytask.taskapp.models import Notification |
4 |
||
5 |
def create_notification(to,subject,message): |
|
6 |
""" |
|
7 |
creates a notification based on the passed arguments. |
|
8 |
to - a list of users to which the notification is to be sent |
|
9 |
subject - subject of the notification message to be sent |
|
10 |
message - message body of the notification |
|
11 |
""" |
|
12 |
notification = Notification(sent_date = datetime.now()) |
|
13 |
notification.save() |
|
123 | 14 |
notification.sent_to = to |
57 | 15 |
notification.sub = subject |
16 |
notification.message = message |
|
17 |
notification.save() |
|
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
18 |
|
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
19 |
def mark_notification_read(notification_id): |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
20 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
21 |
makes a notification identified by the notification_id read. |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
22 |
arguments: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
23 |
notification_id - a number denoting the id of the Notification object |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
24 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
25 |
try: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
26 |
notification = Notification.objects.get(id = notification_id) |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
27 |
except Notification.DoesNotExist: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
28 |
return False |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
29 |
notification.is_read = True |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
30 |
notification.save() |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
31 |
return True |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
32 |
|
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
33 |
def delete_notification(notification_id): |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
34 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
35 |
deletes a notification identified by the notification_id. |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
36 |
arguments: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
37 |
notification_id - a number denoting the id of the Notification object |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
38 |
""" |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
39 |
try: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
40 |
notification = Notification.objects.get(id = notification_id) |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
41 |
except Notification.DoesNotExist: |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
42 |
return False |
123 | 43 |
notification.is_deleted = True |
78
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
44 |
notification.save() |
c5bcafccc135
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents:
57
diff
changeset
|
45 |
return True |
123 | 46 |
|
47 |
def get_notification(nid, user): |
|
48 |
""" if notification exists, and belongs to the current user, return it. |
|
49 |
else return None. |
|
50 |
""" |
|
51 |
||
52 |
try: |
|
53 |
notify_obj = Notification.objects.get(id=nid) |
|
54 |
except Notification.DoesNotExist: |
|
55 |
return None |
|
56 |
||
57 |
try: |
|
58 |
notify_obj.sent_to.get(id=user.id) |
|
59 |
except User.DoesNotExist: |
|
60 |
return None |
|
61 |
||
62 |
if not notify_obj.is_deleted: |
|
63 |
return notify_obj |