taskapp/events/request.py
changeset 145 0c97a02b9bdb
parent 143 796ff9e279a8
child 146 047473d49b25
--- a/taskapp/events/request.py	Sun Feb 28 14:58:11 2010 +0530
+++ b/taskapp/events/request.py	Sun Feb 28 15:59:47 2010 +0530
@@ -64,6 +64,16 @@
                 ## drop a welcome message to that fucker
                 changeRole(role=request_obj.role, user=request_obj.replied_by)
                 create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
+
+                ## here we look for requests that are similar => requesting for DV and make them invalid
+                ## also we drop a notification to user who made request
+                pending_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False,role="DV")
+                for req in pending_requests:
+                    req.is_valid = False
+                    req.save()
+                    create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \
+                                        remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \
+                                        requested_by = req.sent_by )
             else:
                 create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)
 
@@ -75,6 +85,17 @@
                 alerting_users = Profile.objects.filter(user__is_active=True).exclude(rights="CT").exclude(rights="DV")
                 for a_profile in alerting_users:
                     create_notification(request_obj.role, a_profile.user, request_obj.replied_by, reply, requested_by=request_obj.sent_by)
+
+                ## here we look for requests that less or similar => requesting for DV or MG and make them invalid
+                ## also we drop a notification to user who made request
+                active_requests = request_obj.replied_by.request_sent_to.filter(is_valid=True,is_replied=False)
+                pending_requests = active_requests.filter(role="DV") | active_requests.filter(role="MG")
+                for req in pending_requests:
+                    req.is_valid = False
+                    req.save()
+                    create_notification(role = req.role, sent_to = req.sent_by, sent_from = replied_by, reply = False, \
+                                        remarks = "User has accepted a similar request and has rights same or higher privileged than the request", \
+                                        requested_by = req.sent_by )
             else:
                 create_notification(request_obj.role, request_obj.sent_by, request_obj.replied_by, reply, remarks=request_obj.remarks, requested_by=request_obj.sent_by)