def task_add_to_milestone(request, milestone_id=None, response_format='html'): "Task add to preselected project" milestone = None if milestone_id: milestone = get_object_or_404(Milestone, pk=milestone_id) if not request.user.get_profile().has_permission(milestone, mode='x'): milestone = None project = milestone.project project_id = milestone.project.id if request.POST: if not 'cancel' in request.POST: task = Task() form = TaskForm(request.user.get_profile(), None, project_id, milestone_id, request.POST, instance=task) if form.is_valid(): task = form.save() task.set_user_from_request(request) return HttpResponseRedirect(reverse('projects_task_view', args=[task.id])) else: return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id])) else: form = TaskForm(request.user.get_profile(), None, project_id, milestone_id) context = _get_default_context(request) context.update({'form': form, 'project':project, 'milestone':milestone}) return render_to_response('projects/task_add_to_milestone', context, context_instance=RequestContext(request), response_format=response_format)
def task_add_subtask(request, task_id=None, response_format='html'): "New subtask form" parent = None if task_id: parent = get_object_or_404(Task, pk=task_id) if not request.user.get_profile().has_permission(parent, mode='x'): parent = None if request.POST: if not 'cancel' in request.POST: task = Task() form = TaskForm(request.user.get_profile(), parent, None, None, request.POST, instance=task) if form.is_valid(): task = form.save() task.set_user_from_request(request) return HttpResponseRedirect(reverse('projects_task_view', args=[parent.id])) else: return HttpResponseRedirect(reverse('projects_task_view', args=[parent.id])) else: form = TaskForm(request.user.get_profile(), parent, None, None) context = _get_default_context(request) context.update({'form': form, 'task': parent}) return render_to_response('projects/task_add_subtask', context, context_instance=RequestContext(request), response_format=response_format)
def task_add(request, response_format='html'): "New task form" if request.POST: if not 'cancel' in request.POST: task = Task() form = TaskForm(request.user.get_profile(), None, None, None, request.POST, instance=task) if form.is_valid(): task = form.save() task.set_user_from_request(request) return HttpResponseRedirect(reverse('projects_task_view', args=[task.id])) else: return HttpResponseRedirect(reverse('projects')) else: form = TaskForm(request.user.get_profile(), None, None, None) context = _get_default_context(request) context.update({'form': form}) return render_to_response('projects/task_add', context, context_instance=RequestContext(request), response_format=response_format)
def task_edit(request, task_id, response_format='html'): "Task edit page" task = get_object_or_404(Task, pk=task_id) if not request.user.get_profile().has_permission(task, mode='w'): return user_denied(request, message="You don't have access to this Task") if request.POST: if not 'cancel' in request.POST: form = TaskForm(request.user.get_profile(), None, None, None, request.POST, instance=task) if form.is_valid(): task = form.save() return HttpResponseRedirect(reverse('projects_task_view', args=[task.id])) else: return HttpResponseRedirect(reverse('projects_task_view', args=[task.id])) else: form = TaskForm(request.user.get_profile(), None, None, None, instance=task) context = _get_default_context(request) context.update({'form': form, 'task': task} ) return render_to_response('projects/task_edit', context, context_instance=RequestContext(request), response_format=response_format)