Exemplo n.º 1
0
def inbox_item_detail(request, inbox_item_id, template_name='pomodoro/inbox_item_detail.html'):
    inbox_item = get_object_or_404(InboxItem, id=inbox_item_id)
    # retrieve details
    if request.method == 'GET':
        return render_to_response(
                template_name,
                {
                    'inbox_item': inbox_item,
                },
                context_instance=RequestContext(request),
            )
        # update existing resource
    elif request.method == 'POST':
        form = InboxItemForm(request.POST, instance=inbox_item)
        # if form saves, return detail for saved resource
        if form.is_valid():
            inbox_item = form.save()
            return render_to_response(
                    template_name,
                    {
                        'inbox_item': inbox_item,
                        },
                    context_instance=RequestContext(request),
                    )
            # if save fails, go back to edit_resource page
        else:
            return render_to_response(
                    'pomodoro/edit_inbox_item.html',
                    {
                        'form': form,
                        'inbox_item': inbox_item,
                        },
                    context_instance=RequestContext(request),
                    )
Exemplo n.º 2
0
def inbox_items_index(request, template_name='pomodoro/inbox_items_index.html'):
    if request.method == 'GET':
        inbox_items = InboxItem.objects.filter(dealt_with=False)
        return render_to_response(
                template_name,
                {
                    'inbox_items': inbox_items,
                    },
                context_instance=RequestContext(request),
                )
    elif request.method == 'POST':
        form = InboxItemForm(request.POST)
        if form.is_valid():
            inbox_item = form.save()
            # get current task_sheet
            task_sheet = TaskSheet.objects.get_current()
            if task_sheet:
                return HttpResponseRedirect(reverse('task_sheet_detail', kwargs={'task_sheet_id': task_sheet.id,}))
            else:
                return HttpResponseRedirect(reverse('home'))
        else:
            template_name = 'pomodoro/new_inbox_item.html'
            return render_to_response(
                    template_name,
                    {
                        'form': form,
                        'task_sheet': task_sheet,
                        },
                    context_instance=RequestContext(request),
                    )