pytask/profile/utils.py
author Nishanth Amuluru <nishanth@fossee.in>
Sat, 08 Jan 2011 11:20:57 +0530
changeset 69 c6bca38c1cbf
parent 50 profile/utils.py@869a9ab7e2df
child 140 8fcde6f8f750
permissions -rw-r--r--
Added buildout stuff and made changes accordingly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
869a9ab7e2df fixed few typos
Nishanth Amuluru <nishanth@fossee.in>
parents: 46
diff changeset
     1
from pytask.profile.models import Notification
46
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
     2
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
     3
def get_notification(nid, user):
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
     4
    """ 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
     5
    else return None.
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
     6
    """
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
     7
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
     8
    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
     9
    current_notifications = user_notifications.filter(uniq_key=nid)
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    10
    if user_notifications:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    11
        current_notification = current_notifications[0]
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    12
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    13
        try:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    14
            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
    15
            newest_notification = user_notifications.reverse()[0]
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    16
            if newest_notification == newer_notification:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    17
                newest_notification = None
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    18
        except Notification.DoesNotExist:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    19
            newest_notification, newer_notification = None, None
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    20
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    21
        try:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    22
            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
    23
            oldest_notification = user_notifications[0]
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    24
            if oldest_notification == older_notification:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    25
                oldest_notification = None
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    26
        except:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    27
            oldest_notification, older_notification = None, None
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    28
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    29
        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
    30
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    31
    else:
72db9563fae1 created a function for viewign notifications
Nishanth Amuluru <nishanth@fossee.in>
parents: 10
diff changeset
    32
        return None, None, None, None, None