Ejemplo n.º 1
0
def task_sheet_detail(request, task_sheet_id, template_name='pomodoro/task_sheet_detail.html'):
    try:
        task_sheet = TaskSheet.objects.select_related().get(id=task_sheet_id)
    except TaskSheet.DoesNotExist:
        raise Http404('No TaskSheet matches the given query.')

    # retrieve details
    if request.method == 'POST':
        form = TaskSheetForm(request.POST, instance=task_sheet)
        # if form saves, return detail for saved resource
        if form.is_valid():
            task_sheet = form.save()
        # if save fails, go back to edit_resource page
        else:
            return render_to_response(
                    'pomodoro/edit_task_sheet.html',
                    {
                        'form': form,
                        'task_sheet': task_sheet,
                        },
                    context_instance=RequestContext(request),
                    )
    inbox_item_form = InboxItemForm()
    task_form = TaskForm()
    current_pomodoro = Pomodoro.objects.get_current()
    return render_to_response(
            template_name,
            {
                'task_sheet': task_sheet,
                'inbox_item_form': inbox_item_form,
                'task_form': task_form,
                'current_pomodoro': current_pomodoro,
                },
            context_instance=RequestContext(request),
            )
Ejemplo n.º 2
0
def task_sheets_index(request, template_name='pomodoro/task_sheets_index.html'):
    if request.method == 'GET':
        task_sheets = TaskSheet.objects.all()
        return render_to_response(
                template_name,
                {
                    'task_sheets': task_sheets,
                    },
                context_instance=RequestContext(request),
                )
    elif request.method == 'POST':
        form = TaskSheetForm(request.POST)
        if form.is_valid():
            task_sheet = form.save()
            return HttpResponseRedirect(
                    reverse('task_sheet_detail', kwargs={'task_sheet_id': task_sheet.id}))
        else:
            return render_to_response(
                    'pomodoro/new_task_sheet.html',
                    {
                        'form': form,
                        },
                    context_instance=RequestContext(request),
                    )