taskapp/views/task.py
changeset 158 c43e0114e593
parent 157 65d5e9737d1c
child 159 a74a32a5a3e1
equal deleted inserted replaced
157:65d5e9737d1c 158:c43e0114e593
   376         choices = [ (_.id,_.username) for _ in assigned_users ]
   376         choices = [ (_.id,_.username) for _ in assigned_users ]
   377         context = {
   377         context = {
   378             'user':user,
   378             'user':user,
   379             'task':task,
   379             'task':task,
   380         }
   380         }
   381 
   381         
   382         if assigned_users:
   382         if task.status in ["OP", "WR"]:
   383             form = RemoveUserForm(choices)
   383             if assigned_users:
   384             context['form'] = form
   384                 form = RemoveUserForm(choices)
   385             if request.method == "POST":
   385                 context['form'] = form
   386                 data = request.POST
   386                 if request.method == "POST":
   387                 form = RemoveUserForm(choices, data)
   387                     data = request.POST
   388                 if form.is_valid():
   388                     form = RemoveUserForm(choices, data)
   389                     data = form.cleaned_data
   389                     if form.is_valid():
   390                     uid = data['user']
   390                         data = form.cleaned_data
   391                     rem_user = User.objects.get(id=uid)
   391                         uid = data['user']
   392                     removeUser(task, rem_user, user)
   392                         reason = data['reason']
   393                     return redirect(task_url)
   393                         rem_user = User.objects.get(id=uid)
   394                 else:
   394                         removeUser(task, rem_user, user, reason)
   395                     context['form'] = form
   395                         return redirect(task_url)
   396                     return render_to_response('task/remove_user.html', context)
   396                     else:
   397             else:
   397                         context['form'] = form
   398                 return render_to_response('task/remove_user.html',context)
   398                         return render_to_response('task/remove_user.html', context)
   399         else:
   399                 else:
   400             return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task")
   400                     return render_to_response('task/remove_user.html',context)
       
   401             else:
       
   402                 return show_msg(user, "There is no one working on this task to be kicked off", task_url, "view the task")
       
   403         else:
       
   404             return show_msg(user, "This is not the stage to remove users", task_url, "view the task")
   401     else:
   405     else:
   402         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   406         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   403 
   407 
   404 def assign_task(request, tid):
   408 def assign_task(request, tid):
   405     """ first get the status of the task and then assign it to one of claimed users
   409     """ first get the status of the task and then assign it to one of claimed users
   452     
   456     
   453     user = get_user(request.user) if request.user.is_authenticated() else request.user
   457     user = get_user(request.user) if request.user.is_authenticated() else request.user
   454     task = getTask(tid)
   458     task = getTask(tid)
   455 
   459 
   456     ## the moment we see that user had requested credits, it means he had worked and hence we change the status to WR
   460     ## the moment we see that user had requested credits, it means he had worked and hence we change the status to WR
       
   461     ## we have to discuss on this since, credits may also be given to mentor
   457     task.status = "WR"
   462     task.status = "WR"
   458     task.save()
   463     task.save()
   459 
   464 
   460     is_guest = True if not user.is_authenticated() else False
   465     is_guest = True if not user.is_authenticated() else False
   461     is_mentor = True if (not is_guest) and user in task.mentors.all() else False
   466     is_mentor = True if (not is_guest) and user in task.mentors.all() else False