Beispiel #1
0
def tasks_index(request, task_sheet_id, template_name='pomodoro/tasks_index.html'):
    task_sheet = get_object_or_404(TaskSheet, id=task_sheet_id)
    if request.method == 'GET':
        tasks = Task.objects.filter(task_sheet=task_sheet)
        return render_to_response(
                template_name,
                {
                    'task_sheet': task_sheet,
                    'tasks': tasks,
                    },
                context_instance=RequestContext(request),
                )
    elif request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save(commit=False)
            task.task_sheet = task_sheet
            task.save()
            return HttpResponseRedirect(reverse('task_sheet_detail', kwargs={'task_sheet_id': task_sheet.id,}))
        else:
            template_name = 'pomodoro/new_task.html'
            return render_to_response(
                    template_name,
                    {
                        'form': form,
                        'task_sheet': task_sheet,
                        },
                    context_instance=RequestContext(request),
                    )
Beispiel #2
0
def task_detail(request, task_sheet_id, task_id, template_name='pomodoro/task_detail.html'):
    task_sheet = get_object_or_404(TaskSheet, id=task_sheet_id)
    task = get_object_or_404(Task, id=task_id)
    # retrieve details
    if request.method == 'GET':
        return render_to_response(
                template_name,
                {
                    'task': task,
                    'task_sheet': task_sheet,
                    },
                context_instance=RequestContext(request),
                )
        # update existing resource
    elif request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        # if form saves, return detail for saved resource
        if form.is_valid():
            task = form.save()
            return render_to_response(
                    template_name,
                    {
                        'task': task,
                        'task_sheet': task_sheet,
                        },
                    context_instance=RequestContext(request),
                    )
            # if save fails, go back to edit_resource page
        else:
            return render_to_response(
                    'pomodoro/edit_task.html',
                    {
                        'form': form,
                        'task': task,
                        'task_sheet': task_sheet,
                        },
                    context_instance=RequestContext(request),
                    )