Exemplo n.º 1
0
def showItem(request, item_id=1):
    if request.POST:
        form = NotificationForm(request.POST)
        if form.is_valid():
            # do not save yet, and add in default owners_id
            obj = form.save(commit=False)
            # add in the creator's id
            obj.requestedFrom = request.user
            obj.requestedTo = Items.objects.get(id=item_id).owners
            obj.item = Items.objects.get(id=item_id)
            obj.state = "Pending"
            # save data
            obj.save()

            return HttpResponseRedirect("/web/main/")
    else:
        form = NotificationForm()

    args = {}
    args.update(csrf(request))

    args["form"] = form
    args["item"] = Items.objects.get(id=item_id)
    args["notifications"] = Notifications.objects.filter(requestedTo=request.user, state="Pending")
    args["notifications_count"] = args["notifications"].count()
    args["transactions"] = Notifications.objects.filter(requestedFrom=request.user).order_by("item", "-bid")
    args["transactions_count"] = args["transactions"].count()
    args["online_user"] = request.user

    return render_to_response("showItem.html", args)