taskapp/views/task.py
changeset 181 be8ad7e26176
parent 180 972745147e3f
child 191 3bfe70742aa8
equal deleted inserted replaced
180:972745147e3f 181:be8ad7e26176
   528 
   528 
   529     is_mentor = True if user in task.mentors.all() else False
   529     is_mentor = True if user in task.mentors.all() else False
   530     can_edit = True if is_mentor and task.status == "UP" else False
   530     can_edit = True if is_mentor and task.status == "UP" else False
   531 
   531 
   532     if can_edit:
   532     if can_edit:
   533         form = EditTaskForm(task)
   533         form = EditTaskForm(instance=task)
   534         if request.method=="POST":
   534         if request.method=="POST":
   535             data = request.POST
   535             data = request.POST
   536             form = EditTaskForm(task, data)
   536             form = EditTaskForm(data, instance=task)
   537             if form.is_valid():
   537             if form.is_valid():
   538                 data = form.cleaned_data
   538                 form.save()
   539                 title = data['title']
       
   540                 try:
       
   541                     prev_task = Task.objects.exclude(status="DL").get(title__iexact=title)
       
   542                     if prev_task != task:
       
   543                         error_msg = "Another task exists with the same title"
       
   544                         return render_to_response('task/edittask.html',{'user':user, 'form':form, 'error_msg':error_msg})
       
   545                 except Task.DoesNotExist:
       
   546                     pass
       
   547                 task.title = title
       
   548                 task.desc = data['desc']
       
   549                 task.tags_field = data['tags_field']
       
   550                 task.credits = data['credits']
       
   551                 task.save()
       
   552                 return redirect(task_url)
   539                 return redirect(task_url)
   553             else:
   540             else:
   554                 return render_to_response('task/edittask.html',{'user':user, 'form':form})
   541                 return render_to_response('task/edittask.html',{'user':user, 'form':form})
   555         else:
   542         else:
   556             return render_to_response('task/edittask.html',{'user':user, 'form':form})
   543             return render_to_response('task/edittask.html',{'user':user, 'form':form})
   632         else:
   619         else:
   633             return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task")
   620             return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task")
   634     else:
   621     else:
   635         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   622         return show_msg(user, "You are not authorised to do this", task_url, "view the task")
   636 
   623 
   637 
       
   638 def delete_task(request, tid):
   624 def delete_task(request, tid):
   639     """ mark the task status as DL.
   625     """ mark the task status as DL.
   640     take a reason from the user and pass on to all the other mentors.
   626     take a reason from the user and pass on to all the other mentors.
   641     """
   627     """
   642 
   628