def edit_subtask(request, subtask_id, owner_name=None): """ Display full details of a SubTask. Note : Only owners of a subtask can (fully) edit the subtask (and that too only in their own page, ie. not while visiting some other user's page) Coords who have been assigned the SubTask can change only the Status. TODO : Validation Have an Edit Subtask view (like for Tasks)? """ page_owner = get_page_owner(request, owner_name) user = request.user curr_subtask = SubTask.objects.get(id=subtask_id) curr_subtask_form = SubTaskForm(instance=curr_subtask) if curr_subtask.is_owner(user): is_owner = True else: # User is a Coord is_owner = False has_updated = False other_errors = False if request.method == 'POST': if is_owner: # Let the Core save the SubTask curr_subtask_form = SubTaskForm(request.POST, instance=curr_subtask) if curr_subtask_form.is_valid(): curr_subtask_form.save() has_updated = True else: other_errors = True elif 'status' in request.POST: # Coord - allowed to change only the status curr_subtask.status = request.POST.get('status', 'O') curr_subtask.save() has_updated = True # Reinstantiate the form curr_subtask_form = SubTaskForm(instance=curr_subtask) print 'SubTask updated' comments, comment_form, comment_status = handle_comment( request=request, is_task_comment=False, object_id=subtask_id, other_errors=other_errors) if has_updated: # Redirect to the same page, at Vivek's request return redirect('tasks.views.edit_subtask', owner_name=owner_name, subtask_id=subtask_id) else: return render_to_response('tasks/edit_subtask.html', locals(), context_instance=global_context(request))