author | Nishanth Amuluru <nishanth@fossee.in> |
Wed, 12 Jan 2011 00:22:27 +0530 | |
changeset 149 | 32dd15eaf9d0 |
parent 140 | 8fcde6f8f750 |
permissions | -rw-r--r-- |
140
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
1 |
from django.http import Http404 |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
2 |
from django.contrib.auth.models import User |
50 | 3 |
from pytask.profile.models import Notification |
46
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
4 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
5 |
def get_notification(nid, user): |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
6 |
""" if notification exists, and belongs to the current user, return it. |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
7 |
else return None. |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
8 |
""" |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
9 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
10 |
user_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date') |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
11 |
current_notifications = user_notifications.filter(uniq_key=nid) |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
12 |
if user_notifications: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
13 |
current_notification = current_notifications[0] |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
14 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
15 |
try: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
16 |
newer_notification = current_notification.get_next_by_sent_date(sent_to=user, is_deleted=False) |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
17 |
newest_notification = user_notifications.reverse()[0] |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
18 |
if newest_notification == newer_notification: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
19 |
newest_notification = None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
20 |
except Notification.DoesNotExist: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
21 |
newest_notification, newer_notification = None, None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
22 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
23 |
try: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
24 |
older_notification = current_notification.get_previous_by_sent_date(sent_to=user, is_deleted=False) |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
25 |
oldest_notification = user_notifications[0] |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
26 |
if oldest_notification == older_notification: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
27 |
oldest_notification = None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
28 |
except: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
29 |
oldest_notification, older_notification = None, None |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
30 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
31 |
return newest_notification, newer_notification, current_notification, older_notification, oldest_notification |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
32 |
|
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
33 |
else: |
72db9563fae1
created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
10
diff
changeset
|
34 |
return None, None, None, None, None |
140
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
35 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
36 |
def get_user(uid): |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
37 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
38 |
try: |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
39 |
user = User.objects.get(id=uid) |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
40 |
except User.DoesNotExist: |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
41 |
raise Http404 |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
42 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
43 |
if user.is_active: |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
44 |
return user |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
45 |
else: |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
46 |
raise Http404 |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
69
diff
changeset
|
47 |