taskapp/views/task.py
changeset 159 a74a32a5a3e1
parent 158 c43e0114e593
child 160 05157d35d66f
equal deleted inserted replaced
158:c43e0114e593 159:a74a32a5a3e1
   281     task = getTask(tid)
   281     task = getTask(tid)
   282 
   282 
   283     is_guest = True if not user.is_authenticated() else False
   283     is_guest = True if not user.is_authenticated() else False
   284     if (not is_guest) and user in task.mentors.all():
   284     if (not is_guest) and user in task.mentors.all():
   285 
   285 
   286         deps, subs = task.deps, task.subs
   286         if task.status in ["UP", "LO", "OP"]:
   287         task_list = deps if task.sub_type == "D" else subs
   287             
   288 
   288             deps, subs = task.deps, task.subs
   289         if task_list:
   289             task_list = deps if task.sub_type == "D" else subs
   290             choices = [(_.id,_.title) for _ in task_list ]
   290 
   291             form = ChoiceForm(choices)
   291             if task_list:
   292 
   292                 choices = [(_.id,_.title) for _ in task_list ]
   293             errors = []
   293                 form = ChoiceForm(choices)
   294 
   294 
   295             if request.method == "POST":
   295                 errors = []
   296                 data = request.POST
   296                 
   297                 if not data.get('choice', None): errors.append("Please choose a task to remove.")
   297                 context = {
   298                 if not errors:
   298                     'user':user,
   299                     tid = data['choice']
   299                     'task':task,
   300                     sub_task = getTask(tid)
   300                     'form':form,
   301                     removeTask(task, sub_task)
   301                 }
   302                     return redirect(task_url)
   302 
   303                 else:
   303                 if request.method == "POST":
   304                     return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors})
   304                     data = request.POST
   305             else:
   305                     if not data.get('choice', None):
   306                 return render_to_response('task/removetask.html', {'user':user, 'form':form, 'errors':errors})
   306                         errors.append("Please choose a task to remove.")
   307         else:
   307                         context['errors'] = errors
   308             return show_msg(user, "The task has no subtasks/dependencies to be removed", task_url, "view the task")
   308                     if not errors:
       
   309                         tid = data['choice']
       
   310                         sub_task = getTask(tid)
       
   311                         removeTask(task, sub_task)
       
   312                         return redirect(task_url)
       
   313                     else:
       
   314                         return render_to_response('task/removetask.html', context)
       
   315                 else:
       
   316                     return render_to_response('task/removetask.html', context)
       
   317             else:
       
   318                 return show_msg(user, "The task has no subtasks/dependencies to be removed", task_url, "view the task")
       
   319         else:
       
   320             return show_msg(user, "subtasks/dependencies cannot be removed at this stage", task_url, "view the task")
   309     else:
   321     else:
   310         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   322         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   311 
   323 
   312 def claim_task(request, tid):
   324 def claim_task(request, tid):
   313     """ display a list of claims for get and display submit only if claimable """
   325     """ display a list of claims for get and display submit only if claimable """
   581                     closeTask(task, user, data['reason'])
   593                     closeTask(task, user, data['reason'])
   582                     return show_msg(user, "The task has been closed.", task_url, "view the task.")
   594                     return show_msg(user, "The task has been closed.", task_url, "view the task.")
   583             else:
   595             else:
   584                 return render_to_response('task/close.html', context)
   596                 return render_to_response('task/close.html', context)
   585         else:
   597         else:
   586             return show_msg(user, "The task is already closed or the task cannot be closed at this stage", task_url, "view the task")
   598             return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task")
   587     else:
   599     else:
   588         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   600         return show_msg(user, "You are not authorised to do this", task_url, "view the task")