Exemplo n.º 1
0
def update(request, item_id):
    item = get_object_or_404(Item, pk=item_id)
    # assignment = item.group.get_assignment(request.user)
    if request.user != item.wisher:
        print "user is not allowed to edit this item"
        raise PermissionDenied("Only the wisher can edit an item")

    print "Update item: %s" % item
    if request.POST:
        print "posted values %s" % request.POST
        item_form = ItemForm(request.POST, instance=item, user=request.user)
        if not item_form.is_valid():
            return render(request, 'wishlist_app/item/update_item.html',
                          {'item_form': item_form,
                           'item': item,
                           # 'assignment': assignment
                           })
        u_item = item_form.save(commit=False)
        if u_item.quantity is None or int(u_item.quantity) < 1:
            print "item quantity less than 1, defaulting to 1"
            u_item.quantity = 1
        saved_item = item_form.save()
        item_form.save_m2m()
        print "update item %s" % saved_item
        return redirect("item_read", item.id)
    else:
        item_form = ItemForm(instance=item, user=request.user)
        return render(request, 'wishlist_app/item/update_item.html',
                      {'item_form': item_form,
                       'item': item,
                       # 'assignment': assignment
                       })
Exemplo n.º 2
0
def create(request):
    print "Creating a new item"
    print "Wisher: %s" % request.user
    if request.POST:
        print "posted values %s" % request.POST
        item_form = ItemForm(request.POST, user=request.user)
        if not item_form.is_valid():
            return render(request, 'wishlist_app/item/new_item.html',
                          {'item_form': item_form})
        item = item_form.save(commit=False)
        item.wisher = request.user
        item.save()
        item_form.save_m2m()
        print "creating a new item %s" % item
        return redirect("my_wishlist")
    else:
        item_form = ItemForm(user=request.user)
        return render(request, 'wishlist_app/item/new_item.html',
                      {'item_form': item_form})
Exemplo n.º 3
0
def create(request, group_id):
    group = get_object_or_404(WishlistGroup, pk=group_id)
    print "Wisher: %s" % request.user
    if request.POST:
        print "posted values %s" % request.POST
        item_form = ItemForm(request.POST, user=request.user)
        if not item_form.is_valid():
            return render(request, 'wishlist_app/item/new_item.html',
                          {'item_form': item_form,
                           "group": group})
        item = item_form.save(commit=False)
        item.wisher = request.user
        item.save()
        item_form.save_m2m()
        print "creating a new item %s" % item
        print "redirecting to the group home page"
        return redirect("group_home", group.id)
    else:
        item_form = ItemForm(group=group, user=request.user)
        return render(request, 'wishlist_app/item/new_item.html',
                      {'item_form': item_form,
                       "group": group})