Example #1
0
def item_edit(request, pk):
    item = get_object_or_404(Item, pk=pk)
    if item.container.owner != request.user:
        raise Http404("not allowed")
    form = AddItemForm(
        request.POST or None, request.FILES or None, instance=item
    )
    if request.method == 'POST':
        if form.is_valid():
            form.save()
        return {
            'redirect': 'catalog:container',
            'redirect-args': (form.instance.container.pk,)
        }
    return {'form': form}
Example #2
0
def item_add(request, pk=None):
    container = get_object_or_404(Container, pk=pk) if pk else None
    if container:
        if container.owner != request.user:
            raise Http404("not allowed")
    form = AddItemForm(request.POST or None, request.FILES or None, initial={
        'container': container or None
    })

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return {
                'redirect': 'catalog:container',
                'redirect-args': (form.instance.container.pk,)
            }
    return {'form': form}