taskapp/utilities/request.py
author anoop
Wed, 24 Feb 2010 16:49:30 +0530
changeset 78 c5bcafccc135
parent 71 801cf8fca53a
child 80 8917b190c4c4
permissions -rw-r--r--
added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     1
from pytask.taskapp.models import Request
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     2
from datetime import datetime
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     3
71
801cf8fca53a made change to the request model and corresponding create_request utility.
anoop
parents: 58
diff changeset
     4
def create_request(to,by,role,task=None,assigned_user=None):
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     5
    """
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     6
    creates an unreplied request, based on the passed arguments
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     7
        to - a list of users to which the notification is to be sent
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     8
        by - sender of request
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     9
        role - a two character field which represents the role requested
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    10
        task - a requesting task (useful for sending admins a request to give Pynts to the user)
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    11
        assigned_user - user to whom the Pynts/Task is assigned to(useful for sending admins a request to give Pynts to the user)
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    12
    """
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    13
    req = Request(creation_date=datetime.now())
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    14
    req.by = by
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    15
    req.reply_date = datetime(1970,01,01)
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    16
    req.save()
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    17
    req.to = to
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    18
    req.role = role
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    19
    if task is not None:
71
801cf8fca53a made change to the request model and corresponding create_request utility.
anoop
parents: 58
diff changeset
    20
        req.task = task
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    21
    if assigned_user is not None:
71
801cf8fca53a made change to the request model and corresponding create_request utility.
anoop
parents: 58
diff changeset
    22
        req.assigned_user = assigned_user
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    23
    req.save()
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    24
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    25
def reply_to_request(request_id, reply):
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    26
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    27
    makes a request replied with the given reply.
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    28
    arguments:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    29
        request_id - a number denoting the id of the Request object
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    30
        reply - a boolean value to be given as reply (True/False)
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    31
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    32
    try:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    33
        request = Request.objects.get(id = request_id)
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    34
    except Request.DoesNotExist:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    35
        return False #No such request exist
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    36
    if request.replied is not True:
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    37
        request.reply = reply
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    38
        request.replied = True
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    39
        request.read = True
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    40
        request.reply_date = datetime.now()
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    41
        request.save()
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    42
        return True #Reply has been added successfully
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    43
    return False #Already replied