def view_list_add_to_existing(request, list_id):
    list_ = List.objects.get(id=list_id)
    form = mocked_models.ItemForm()

    if request.method == 'POST':
        form = mocked_models.ItemForm(data=request.POST)
        if form.is_valid():
            form.save(list_=list_)
            return (redirect(list_))
    return render(request, 'list.html', {'list': list_, 'form': form})
def view_list(request, list_id):
    list_ = List.objects.get(id=list_id)
    form = mocked_models.ItemForm()

    if list_ is None:
        return HttpResponseNotFound()

    if request.method == 'POST':
        form = mocked_models.ItemForm(data=request.POST)
        if form.is_valid():
            form.save(list_=list_)
            return (redirect(list_))
    return render(request, 'list.html', {'list': list_, 'form': form})
def new_list(request):
    form = mocked_models.ItemForm(data=request.POST)
    if form.is_valid():
        list_ = List.objects.create()
        Item.objects.create(text=request.POST['text'], list=list_)
        return redirect(list_)
    else:
        return render(request, 'home.html', {'form': form})
def view_list_no_redirect_after_post(request, list_id):
    try:
        list_ = List.objects.get(id=list_id)
        if list_ is None:
            raise ObjectDoesNotExist()
    except ObjectDoesNotExist:
        return HttpResponseNotFound()

    if not list_.owned_by(request.user):
        return HttpResponseForbidden()

    form = mocked_models.ItemForm()

    if request.method == 'POST':
        form = mocked_models.ItemForm(data=request.POST)
        if form.is_valid():
            form.save(list_=list_)
    return render(request, 'list.html', {'list': list_, 'form': form})