Пример #1
0
def additional_info(request, auction_id):
    auction = get_object_or_404(Auction.all_objects, pk=auction_id, is_completed=True, winner=request.user)
    if not auction.additional_info_needed():
        raise Http404
    if request.method == "POST":
        if auction.is_abonement():
            additional_info_form = AbonementsAdditionalInfoForm(request.POST, offer=auction)
            if additional_info_form.is_valid():
                additional_info_form.save()
                auction.abonements_additional_info = additional_info_form.instance
                auction.save()
                schedule_fitnesshouse_notification(auction)
                return redirect("cabinet_auctions")
        elif auction.is_additional_service():
            additional_info_form = AbonementsClubCardForm(request.POST, offer=auction)
            if additional_info_form.is_valid():
                additional_info_form.save()
                auction.additional_services_additional_info = additional_info_form.instance
                auction.save()
                schedule_fitnesshouse_notification(auction)
                return redirect("cabinet_auctions")
    else:
        if auction.is_abonement():
            additional_info_form = AbonementsAdditionalInfoForm(offer=auction)
        elif auction.is_additional_service():
            print auction.additional_services_get_user_card_number(request.user)
            additional_info_form = AbonementsClubCardForm(
                offer=auction, initial={"card_number": auction.additional_services_get_user_card_number(request.user)}
            )
    context = RequestContext(request)
    context["auction"] = auction
    context["additional_info_form"] = additional_info_form
    return render_to_response("auctions/abonements_additional_info.html", context)
Пример #2
0
def ajax_additional_info_abonements_validate(request, offer_id):
    if request.method == 'POST':
        offer = get_object_or_404(Offers, pk=offer_id)
        form = AbonementsAdditionalInfoForm(request.POST, offer=offer)
        result = {}
        if form.is_valid():
            tomorrow = now() + datetime.timedelta(days=1)
            result['success'] = True
            context = RequestContext(request)
            context['offer'] = offer
            context['address'] = form.cleaned_data['address']
            context.update(form.cleaned_data)
            context['add_date'] = tomorrow
            context['valid_term'] = u'с %s по %s' % (timezone.localtime(context['add_date']).strftime('%d.%m.%Y'), timezone.localtime((context['add_date'] + datetime.timedelta(days=offer.abonements_term))).strftime('%d.%m.%Y'))
            result['message'] = render_to_string('offers/_additional_services_buy_preview.html', context)
        else:
            result['success'] = False
            context = {}
            context['form'] = form
            result['message'] = render_to_string('_form_errors.html', context)
        return HttpResponse(simplejson.dumps(result))
    else:
        return redirect('home')
Пример #3
0
def buy_view(request, offer, cart_item=None):
    context = RequestContext(request)
    if not offer.can_buy():
        messages.info(request, 'К сожалению, купоны по данной акции закончились')
        return redirect(offer.get_url())
    context['offer'] = offer
    if cart_item is not None:
        cart = ShoppingCart(request)
        context['is_cart_item'] = True
    if cart_item is not None and cart_item['is_gift']:
        #Мы имеем дело с подарком
        return buy_gift_view(request, offer, cart_item)
    elif offer.is_abonement():
        #Мы имеем дело с абонементом
        if request.method == 'POST':
            additional_info_form = AbonementsAdditionalInfoForm(request.POST, offer=offer)
            buy_form = BuyOfferForm(request.POST, user=request.user, offer=offer, initial={'quantity':1})
            if additional_info_form.is_valid() and buy_form.is_valid():
                additional_info_form.save()
                abonement_order = AbonementOrder(offer=offer, user=request.user, visitor_info=request.session['visitor_info'], additional_info=additional_info_form.instance)
                if buy_form.cleaned_data['payment_type'] == 1:
                    #Если выбрали оплату с депозита, сразу списываем деньги и завершаем заказ
                    abonement_order.price = offer.coupon_price_money
                    abonement_order.price_type = 1
                    abonement_order.save()
                    profile = request.user.get_profile()
                    transaction = profile.withdraw_money_deposit(abonement_order.price, u"Оплата заказа %s (%s)" % (abonement_order.pk, offer.title,))
                    abonement_order.complete(transaction)
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return redirect('cabinet_abonements')
                elif buy_form.cleaned_data['payment_type'] == 2:
                    #Аналогично с оплатой бонусами
                    abonement_order.price = offer.coupon_price_bonuses
                    abonement_order.price_type = 2
                    abonement_order.save()
                    profile = request.user.get_profile()
                    transaction = profile.withdraw_bonuses(abonement_order.price, u"Оплата заказа %s (%s)" % (abonement_order.pk, offer.title,))
                    abonement_order.complete(transaction)
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return redirect('cabinet_abonements')
                elif buy_form.cleaned_data['payment_type'] == 3:
                    abonement_order.price = offer.coupon_price_money
                    abonement_order.price_type = 1
                    abonement_order.save()
                    payment_request = PaymentRequest(inner_transaction=abonement_order, amount=abonement_order.price, comment=u"Bonus-House.ru. Оплата заказа #%s. Пользователь #%s" % (abonement_order.pk, abonement_order.user.pk,))
                    payment_request.save()
                    context = RequestContext(request)
                    context['amount'] = abonement_order.price
                    context['nickname'] = request.user.email
                    context['order_id'] = payment_request.pk
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return render_to_response('payments/dol/redirect_form.html', context)
        else:
            if cart_item is not None:
                initial = cart_item['additional_info']
            else:
                initial = None
            initial = {'first_name': request.user.first_name,
                       'last_name': request.user.last_name,
                       'email': request.user.email,
                       'birth_date': request.user.get_profile().birth_date,
                       'phone': request.user.get_profile().phone,
                       'gender': request.user.get_profile().gender}

            additional_info_form = AbonementsAdditionalInfoForm(offer=offer, initial=initial)
            buy_form = BuyOfferForm(user=request.user, offer=offer)
        context['additional_info_form'] = additional_info_form
        context['buy_form'] = buy_form
        return render_to_response('offers/buy_abonements_additional_info.html', context)
    elif offer.is_additional_service():
        #Мы имеем дело с дополнительной услугой к договору
        if request.method == 'POST':
            additional_info_form = AbonementsClubCardForm(request.POST, offer=offer)
            buy_form = BuyOfferForm(request.POST, user=request.user, offer=offer, initial={'quantity':1})
            if additional_info_form.is_valid() and buy_form.is_valid():
                additional_info_form.save()
                order = AdditionalServicesOrder(offer=offer, user=request.user, visitor_info=request.session['visitor_info'], additional_info=additional_info_form.instance)
                if buy_form.cleaned_data['payment_type'] == 1:
                    #Если выбрали оплату с депозита, сразу списываем деньги и завершаем заказ
                    order.price = offer.coupon_price_money
                    order.price_type = 1
                    order.save()
                    profile = request.user.get_profile()
                    transaction = profile.withdraw_money_deposit(order.price, u"Оплата заказа %s (%s)" % (order.pk, offer.title,))
                    order.complete(transaction)
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return redirect('cabinet_abonements')
                elif buy_form.cleaned_data['payment_type'] == 2:
                    #Аналогично с оплатой бонусами
                    order.price = offer.coupon_price_bonuses
                    order.price_type = 2
                    order.save()
                    profile = request.user.get_profile()
                    transaction = profile.withdraw_bonuses(order.price, u"Оплата заказа %s (%s)" % (order.pk, offer.title,))
                    order.complete(transaction)
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return redirect('cabinet_additional_services')
                elif buy_form.cleaned_data['payment_type'] == 3:
                    order.price = offer.coupon_price_money
                    order.price_type = 1
                    order.save()
                    payment_request = PaymentRequest(inner_transaction=order, amount=order.price, comment=u"Bonus-House.ru. Оплата заказа #%s. Пользователь #%s" % (order.pk, order.user.pk,))
                    payment_request.save()
                    context = RequestContext(request)
                    context['amount'] = order.price
                    context['nickname'] = request.user.email
                    context['order_id'] = payment_request.pk
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return render_to_response('payments/dol/redirect_form.html', context)
        else:
            additional_info_form = AbonementsClubCardForm(offer=offer)
            buy_form = BuyOfferForm(user=request.user, offer=offer)
        context['additional_info_form'] = additional_info_form
        context['buy_form'] = buy_form
        return render_to_response('offers/buy_abonements_club_card.html', context)
    else:
        #Это не абонемент и не доп. услуги, а обычная акция
        if request.method == 'POST':
            buy_form = BuyOfferForm(request.POST, user=request.user, offer=offer)
            if buy_form.is_valid():
                #@TODO: Протестировать определение реферера и узнать время, на которое его надо запоминать в сессии.
                order = Order(offer=offer, quantity=buy_form.cleaned_data['quantity'], user=request.user, visitor_info=request.session['visitor_info'])
                if buy_form.cleaned_data['payment_type'] == 1:
                    #Если выбрали оплату с депозита, сразу списываем деньги и завершаем заказ
                    order.price = offer.coupon_price_money * buy_form.cleaned_data['quantity']
                    order.price_type = 1
                    order.save()
                    profile = request.user.get_profile()
                    transaction = profile.withdraw_money_deposit(order.price, u"Оплата заказа %s (%s)" % (order.pk, offer.title,))
                    order.complete(transaction)
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return redirect('cabinet')
                elif buy_form.cleaned_data['payment_type'] == 2:
                    #Аналогично с оплатой бонусами
                    order.price = offer.coupon_price_bonuses * buy_form.cleaned_data['quantity']
                    order.price_type = 2
                    order.save()
                    profile = request.user.get_profile()
                    transaction = profile.withdraw_bonuses(order.price, u"Оплата заказа %s (%s)" % (order.pk, offer.title,))
                    order.complete(transaction)
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return redirect('cabinet')
                elif buy_form.cleaned_data['payment_type'] == 3:
                    order.price = offer.coupon_price_money * buy_form.cleaned_data['quantity']
                    order.price_type = 1
                    order.save()
                    payment_request = PaymentRequest(inner_transaction=order, amount=order.price, comment=u"Bonus-House.ru. Оплата заказа #%s. Пользователь #%s" % (order.pk, order.user.pk,))
                    payment_request.save()
                    context = RequestContext(request)
                    context['amount'] = order.price
                    context['nickname'] = request.user.email
                    context['order_id'] = payment_request.pk
                    if cart_item is not None:
                        cart.remove_item(cart_item['id'])
                    return render_to_response('payments/dol/redirect_form.html', context)
        else:
            if cart_item is not None:
                initial = {'quantity':cart_item['quantity']}
            else:
                initial = None
            initial = {'first_name': request.user.first_name,
                       'last_name': request.user.last_name,
                       'email': request.user.email,
                       'birth_date': request.user.get_profile().birth_date,
                       'phone': request.user.get_profile().phone,
                       'gender': request.user.get_profile().gender}

            additional_info_form = SimpleActionAdditionalInfoForm(offer=offer, initial=initial)
            context['additional_info_form'] = additional_info_form
            buy_form = BuyOfferForm(user=request.user, offer=offer, initial=initial)
            context['buy_form'] = buy_form
            return render_to_response('offers/buy_simple_actions_additional_info.html', context)