Beispiel #1
0
def edit_item(request, item_id):
    try:
        item = Item.objects.get(pk=item_id, seller=request.user.user)
    except Item.DoesNotExist:
        raise Http404

    if item.status == AUCTION_ITEM_STATUS_RUNNING:
        return HttpResponseRedirect(reverse("lebay_view_item_detail", args=[item.pk]))

    if request.method == "POST":
        item_form = ItemForm(data=request.POST, instance=item)

        if item_form.is_valid():
            saved_item = item_form.save()
            return HttpResponseRedirect(reverse("lebay_view_item_detail", args=[saved_item.id]))
    else:
        item_form = ItemForm(instance=item)

    return render_to_response(
        "lebay/edit_item_detail.html", {"item_form": item_form}, context_instance=RequestContext(request)
    )
Beispiel #2
0
def list_item(request):
    try:
        seller_profile = Seller.objects.get(user=request.user.user)
    except Seller.DoesNotExist:
        return HttpResponseRedirect(reverse("lebay_create_seller_profile") + "?next=%s" % reverse("lebay_list_item"))

    if request.method == "POST":
        item_form = ItemForm(data=request.POST, seller=request.user.user)
        auction_form = AuctionEventForm(data=request.POST)

        if item_form.is_valid() and auction_form.is_valid():
            item = item_form.save()
            auction_event = auction_form.save(item=item)
            return HttpResponseRedirect(reverse("lebay_view_auction_event", args=[auction_event.id]))
    else:
        item_form = ItemForm()
        auction_form = AuctionEventForm()

    return render_to_response(
        "lebay/list_item.html",
        {"item_form": item_form, "auction_form": auction_form},
        context_instance=RequestContext(request),
    )