removing user deletes all the pending requests that request giving him pynts.
authornishanth
Mon, 01 Mar 2010 05:18:44 +0530
changeset 158 c43e0114e593
parent 157 65d5e9737d1c
child 159 a74a32a5a3e1
removing user deletes all the pending requests that request giving him pynts.
taskapp/events/task.py
taskapp/views/task.py
--- a/taskapp/events/task.py	Mon Mar 01 04:54:08 2010 +0530
+++ b/taskapp/events/task.py	Mon Mar 01 05:18:44 2010 +0530
@@ -146,6 +146,8 @@
     claim.user = user
     claim.creation_datetime = datetime.now()
     claim.save()
+
+    user.request_sent_to.filter(is_replied=False, is_valid=True, role="MT", task=task).update(is_valid=False)
     
 def assignTask(task, user, assigned_by):
     """ check for the status of task and assign it to the particular user """
@@ -183,13 +185,18 @@
     mapobj.subs.remove(sub_task)
     mapobj.save()
 
-def removeUser(main_task, rem_user, removed_by):
+def removeUser(main_task, rem_user, removed_by, reason=None):
     """ right now, just remove the user from the list of assigned_users.
     """
 
     main_task.assigned_users.remove(rem_user)
     main_task.save()
 
+    ## TODiscuss : when a user is kicked off, his pending requests for pynts is made invalid
+    rem_user.request_receiving_user.filter(task=main_task,role="PY",is_valid=True,is_replied=False).update(is_valid=False)
+
+    ## TODO : create notification to the victim
+
 def assignCredits(task, given_by, given_to, points):
     """ make a proper request object.
     """
--- a/taskapp/views/task.py	Mon Mar 01 04:54:08 2010 +0530
+++ b/taskapp/views/task.py	Mon Mar 01 05:18:44 2010 +0530
@@ -378,26 +378,30 @@
             'user':user,
             'task':task,
         }
-
-        if assigned_users:
-            form = RemoveUserForm(choices)
-            context['form'] = form
-            if request.method == "POST":
-                data = request.POST
-                form = RemoveUserForm(choices, data)
-                if form.is_valid():
-                    data = form.cleaned_data
-                    uid = data['user']
-                    rem_user = User.objects.get(id=uid)
-                    removeUser(task, rem_user, user)
-                    return redirect(task_url)
+        
+        if task.status in ["OP", "WR"]:
+            if assigned_users:
+                form = RemoveUserForm(choices)
+                context['form'] = form
+                if request.method == "POST":
+                    data = request.POST
+                    form = RemoveUserForm(choices, data)
+                    if form.is_valid():
+                        data = form.cleaned_data
+                        uid = data['user']
+                        reason = data['reason']
+                        rem_user = User.objects.get(id=uid)
+                        removeUser(task, rem_user, user, reason)
+                        return redirect(task_url)
+                    else:
+                        context['form'] = form
+                        return render_to_response('task/remove_user.html', context)
                 else:
-                    context['form'] = form
-                    return render_to_response('task/remove_user.html', context)
+                    return render_to_response('task/remove_user.html',context)
             else:
-                return render_to_response('task/remove_user.html',context)
+                return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task")
         else:
-            return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task")
+            return show_msg(user, "This is not the stage to remove users", task_url, "view the task")
     else:
         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
 
@@ -454,6 +458,7 @@
     task = getTask(tid)
 
     ## the moment we see that user had requested credits, it means he had worked and hence we change the status to WR
+    ## we have to discuss on this since, credits may also be given to mentor
     task.status = "WR"
     task.save()