Ejemplo n.º 1
0
def add_bid_form(request, auction_id):
    auction = get_object_or_404(Auction, pk=auction_id)
    context = RequestContext(request)
    if auction.is_additional_service():
        if auction.additional_services_get_user_card_number(request.user):
            context["user_card_number"] = auction.additional_services_get_user_card_number(request.user)
        else:
            return redirect(auction.get_url())
    context["auction"] = auction
    if request.method == "POST":
        bid_form = AddBidForm(
            request.POST, request=request, auction=auction, initial={"amount": auction.get_actual_price()}
        )
        if bid_form.is_valid():
            transaction = AccountDepositTransactions(
                user=request.user,
                amount=-bid_form.cleaned_data["amount"],
                is_completed=True,
                comment=u"Блокировка ставки на аукцион %s" % (auction.title,),
            )
            transaction.save()
            bid = AuctionBid(
                auction=auction, user=request.user, amount=bid_form.cleaned_data["amount"], transaction=transaction
            )
            bid.save()
            # Разблокируем перебитые ставки
            auction.unlock_beaten_bids()
            if bid.amount >= auction.buyout_price:
                # Если достигнута цена выкупа, завершаем аукцион
                auction.complete()
                return redirect("cabinet_auctions")
            else:
                # Продлеваем аукцион в соответствии с настройками
                AUCTIONS_BID_ADD_TIME = Settings.objects.get(key="AUCTIONS_BID_ADD_TIME")
                AUCTIONS_BID_ADD_TIME = AUCTIONS_BID_ADD_TIME.value
                auction.end_date += datetime.timedelta(seconds=int(AUCTIONS_BID_ADD_TIME))
                auction.save()
                messages.info(request, "Спасибо! Ваша ставка принята")
                return redirect(auction.get_url())
    else:
        bid_form = AddBidForm(request=request, auction=auction, initial={"amount": auction.get_actual_price()})
    context["bid_form"] = bid_form
    return render_to_response("auctions/add_bid.html", context)
Ejemplo n.º 2
0
def deposit_account(request):
    context = RequestContext(request)
    if request.method == 'POST':
        deposit_form = DepositForm(request.POST)
        if deposit_form.is_valid():
            deposit = AccountDepositTransactions(user=request.user, amount=deposit_form.cleaned_data['amount'],
                                                 comment='Пополнение личного счета')
            deposit.save()
            payment_request = PaymentRequest(inner_transaction=deposit, amount=deposit.amount,
                                             comment="Bonus-House.ru. Пополнение личного счета. Пользователь #%s"
                                             % (deposit.user.pk,))
            payment_request.save()
            context = RequestContext(request)
            context['amount'] = deposit_form.cleaned_data['amount']
            context['nickname'] = request.user.email
            context['order_id'] = payment_request.pk
            return render_to_response('payments/dol/redirect_form.html', context)
    else:
        deposit_form = DepositForm()
    context['deposit_form'] = deposit_form
    return render_to_response('users/deposit_account.html', context)