taskapp/events/request.py
changeset 218 59107ce0a618
parent 161 74ef330c9185
equal deleted inserted replaced
217:307f699e6102 218:59107ce0a618
     1 from datetime import datetime
     1 from datetime import datetime
     2 from pytask.taskapp.models import Profile
     2 from pytask.taskapp.models import Profile
     3 from pytask.taskapp.events.task import  addMentor
     3 from pytask.taskapp.events.task import  addReviewer
     4 from pytask.taskapp.events.user import changeRole
     4 from pytask.taskapp.events.user import changeRole
     5 from pytask.taskapp.utilities.notification import create_notification
     5 from pytask.taskapp.utilities.notification import create_notification
     6 
     6 
     7 def reply_to_request(request_obj, reply, replied_by):
     7 def reply_to_request(request_obj, reply, replied_by):
     8     """
     8     """
    31 
    31 
    32         elif request_obj.role == "MT":
    32         elif request_obj.role == "MT":
    33             task = request_obj.task
    33             task = request_obj.task
    34             requested_by = request_obj.sent_by
    34             requested_by = request_obj.sent_by
    35             if reply:
    35             if reply:
    36                 ## tell the replied user that he is mentor for this task and give him learn more link
    36                 ## tell the replied user that he is reviewer for this task and give him learn more link
    37                 create_notification("NT", request_obj.replied_by, task=task) 
    37                 create_notification("NT", request_obj.replied_by, task=task) 
    38 
    38 
    39                 ## now check if there are such similar requests and mark them as invalid
    39                 ## now check if there are such similar requests and mark them as invalid
    40                 ## they cannot be of type PY and so we can use the replied_by to get requests
    40                 ## they cannot be of type PY and so we can use the replied_by to get requests
    41                 pending_requests = replied_by.request_sent_to.filter(is_valid=True, is_replied=False, role="MT",task=task)
    41                 pending_requests = replied_by.request_sent_to.filter(is_valid=True, is_replied=False, role="MT",task=task)
    42                 for req in pending_requests:
    42                 for req in pending_requests:
    43                        create_notification("MT", req.sent_by, replied_by, False, task=req.task, remarks = "User has already accepted one such request and is a mentor.", requested_by = req.sent_by)
    43                        create_notification("MT", req.sent_by, replied_by, False, task=req.task, remarks = "User has already accepted one such request and is a reviewer.", requested_by = req.sent_by)
    44                        req.is_valid = False
    44                        req.is_valid = False
    45                        req.save()
    45                        req.save()
    46 
    46 
    47                 ## alert all the mentors including who made request and all assigned users
    47                 ## alert all the reviewers including who made request and all assigned users
    48                 for a_mentor in task.mentors.all():
    48                 for a_reviewer in task.reviewers.all():
    49                     create_notification(request_obj.role, a_mentor, replied_by, True, task, request_obj.remarks, requested_by)
    49                     create_notification(request_obj.role, a_reviewer, replied_by, True, task, request_obj.remarks, requested_by)
    50                 for a_user in task.assigned_users.all():
    50                 for a_user in task.assigned_users.all():
    51                     create_notification(request_obj.role, a_user, replied_by, True, task, request_obj.remarks, requested_by)
    51                     create_notification(request_obj.role, a_user, replied_by, True, task, request_obj.remarks, requested_by)
    52 
    52 
    53                 addMentor(task, request_obj.replied_by)
    53                 addReviewer(task, request_obj.replied_by)
    54             else:
    54             else:
    55                 ## tell the requested user that his request was rejected due to these reasons.
    55                 ## tell the requested user that his request was rejected due to these reasons.
    56                 create_notification(request_obj.role, requested_by, replied_by, False, task, request_obj.remarks, requested_by)
    56                 create_notification(request_obj.role, requested_by, replied_by, False, task, request_obj.remarks, requested_by)
    57 
    57 
    58         elif request_obj.role == "DV":
    58         elif request_obj.role == "DV":