summaryrefslogtreecommitdiff
path: root/taskapp/utilities/request.py
blob: 7c7af708e41aca4f21d5d3f02119baba11c3877e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from datetime import datetime
from django.contrib.auth.models import User
from pytask.taskapp.models import Request, Profile

def create_request(sent_by,role,sent_to=None,task=None,receiving_user=None,pynts=0):
    """
    creates an unreplied request, based on the passed arguments
        sent_to - a list of users to which the notification is to be sent
        sent_by - sender of request
        role - a two character field which represents the role requested, if role = 'PY' then sent to all admins
        task - a requesting task (useful for sending admins a request to give Pynts to the user)
        receiving_user - user to whom the Pynts is assigned to(useful for sending admins a request to give Pynts to the user)
        pynts - the pynts assigned to the receiving user
    """
    req = Request(creation_date=datetime.now())
    req.sent_by = sent_by
    req.reply_date = datetime(1970,01,01)
    req.role = role
    req.pynts = pynts
    if task:
        req.task = task
    req.save()
    if role == 'PY':
        admin_profiles = Profile.objects.filter(rights='AD')
        for admin_profile in admin_profiles:
            req.sent_to.add(admin_profile.user)
        req.receiving_user = receiving_user
    else:
        req.sent_to.add(sent_to)
    req.save()