taskapp/utilities/request.py
author nishanth
Thu, 25 Feb 2010 02:11:49 +0530
changeset 89 1cc03941ed5d
parent 87 f0a3d6612462
child 99 64c34c1f441f
permissions -rw-r--r--
added the capability of adding subtasks/dependencies .
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
     1
from pytask.taskapp.models import Request, Profile
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     2
from datetime import datetime
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
     3
from django.contrib.auth.models import User
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     4
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
     5
def create_request(sent_by,role,sent_to=None,task=None,receiving_user=None,pynts=0):
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     6
    """
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
     7
    creates an unreplied request, based on the passed arguments
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
     8
        sent_to - a list of users to which the notification is to be sent
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
     9
        sent_by - sender of request
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    10
        role - a two character field which represents the role requested, if role = 'PY' then sent to all admins
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    11
        task - a requesting task (useful for sending admins a request to give Pynts to the user)
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    12
        receiving_user - user to whom the Pynts is assigned to(useful for sending admins a request to give Pynts to the user)
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    13
        pynts - the pynts assigned to the receiving user
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    14
    """
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    15
    req = Request(creation_date=datetime.now())
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    16
    req.sent_by = sent_by
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    17
    req.reply_date = datetime(1970,01,01)
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    18
    req.role = role
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    19
    req.pynts = pynts
80
8917b190c4c4 added attribute pynts to request model.
anoop
parents: 78
diff changeset
    20
    if task:
71
801cf8fca53a made change to the request model and corresponding create_request utility.
anoop
parents: 58
diff changeset
    21
        req.task = task
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    22
    req.save()
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    23
    if role == 'PY':
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    24
        admin_profiles = Profile.objects.filter(rights='AD')
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    25
        for admin in admin_profiles:
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    26
            req.sent_to.add(admin_profile.user)
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    27
        req.receiving_user = receiving_user
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    28
    else:
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    29
        req.sent_to.add(sent_to)
58
e0ec1901dfce changed request model, added create_request utility.
anoop
parents:
diff changeset
    30
    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
    31
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    32
def reply_to_request(request_obj, reply, replied_by):
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    33
    """
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    34
    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
    35
    arguments:
82
7c38ff64aee7 changed the method reply_to_request to accept request object instead of request id.
anoop
parents: 81
diff changeset
    36
        request_obj - Request object for which change is intended
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    37
        reply - a boolean value to be given as reply (True/False)
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    38
        replied_by - the user object who replies to the request
78
c5bcafccc135 added utilities reply_to_request, mark_notification_read, delete_notification and made change to create_request utility.
anoop
parents: 71
diff changeset
    39
    """
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    40
    if not request_obj.is_replied:
82
7c38ff64aee7 changed the method reply_to_request to accept request object instead of request id.
anoop
parents: 81
diff changeset
    41
        request_obj.reply = reply
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    42
        request_obj.is_replied = True
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    43
        request_obj.is_read = True
82
7c38ff64aee7 changed the method reply_to_request to accept request object instead of request id.
anoop
parents: 81
diff changeset
    44
        request_obj.reply_date = datetime.now()
87
f0a3d6612462 updated create_request utility.
anoop
parents: 82
diff changeset
    45
        request_obj.replied_by = replied_by
82
7c38ff64aee7 changed the method reply_to_request to accept request object instead of request id.
anoop
parents: 81
diff changeset
    46
        request_obj.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
    47
        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
    48
    return False #Already replied