taskapp/utilities/notification.py
author anoop
Wed, 24 Feb 2010 17:23:25 +0530
changeset 81 cade14d25a58
parent 78 c5bcafccc135
child 123 a6b4234388c8
permissions -rw-r--r--
added pynts in create_request utility.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     1
from pytask.taskapp.models import Notification
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     2
from datetime import datetime
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     3
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     4
def create_notification(to,subject,message):
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     5
    """
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     6
    creates a notification based on the passed arguments.
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     7
        to - a list of users to which the notification is to be sent
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     8
        subject - subject of the notification message to be sent
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
     9
        message - message body of the notification
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    10
    """
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    11
    notification = Notification(sent_date = datetime.now())
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    12
    notification.save()
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    13
    notification.to = to
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    14
    notification.sub = subject
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    15
    notification.message = message
67e0d0a915e3 added utilities for creating notification.
anoop
parents:
diff changeset
    16
    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
    17
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    18
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
    19
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    20
    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
    21
    arguments:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    22
        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
    23
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    24
    try:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    25
        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
    26
    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
    27
        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
    28
    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
    29
    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
    30
    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
    31
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    32
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
    33
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    34
    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
    35
    arguments:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    36
        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
    37
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    38
    try:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    39
        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
    40
    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
    41
        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
    42
    notification.deleted = True
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 57
diff changeset
    43
    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
    44
    return True