Exemplo n.º 1
0
def add_task(request, user_story_id):
    user_story = UserStory.objects.get(pk=user_story_id)
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save(False)
            task.user_story = user_story
            task.developer = request.user
            task.save()
            task_log = TaskLog()
            task_log.current_hours = int(form.cleaned_data['current_hours'])
            task_log.task = task
            task_log.save()
            request.user.message_set.create(message="New task has been added.")
            return HttpResponseRedirect('/sprint/show/' + str(user_story.sprint.id))
    else:
        form = TaskForm()
    return render_to_response('sprint/add-task.html', {'form': form, 'project': user_story.sprint.project}, context_instance=RequestContext(request))
Exemplo n.º 2
0
def edit_task(request, task_id):
    task = Task.objects.get(pk=task_id)
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            task.name = form.cleaned_data['name']
            task.hours = form.cleaned_data['hours']
            task.current_hours = form.cleaned_data['current_hours']
            task.save()
            try:
                task_log = TaskLog.objects.get(task=task, created_at=datetime.date.today())
            except:
                task_log = TaskLog()
            task_log.current_hours = int(form.cleaned_data['current_hours'])
            task_log.task = task
            task_log.save()
            request.user.message_set.create(message="Task has been modified.")
            return HttpResponseRedirect('/sprint/show/' + str(task.user_story.sprint.id))
    else:
        form = TaskForm(instance=task)
    return render_to_response('sprint/edit-task.html', {'form': form, 'project': task.user_story.sprint.project}, context_instance=RequestContext(request))