Esempio n. 1
0
def setup_featured(request, authentication_key):
    account = request.account
    event = Event.events.get(authentication_key__exact=authentication_key)    

    featured_event = FeaturedEvent(
        event=event,
        owner=account,
        start_time=datetime.date.today(),
        end_time=datetime.date.today() + datetime.timedelta(days=15)
    )

    venue_account_featured_stats = FeaturedEvent.objects.filter(event__venue_id=event.venue.id)

    form = SetupFeaturedForm(
        instance=featured_event
    )

    if request.method == 'POST':
        form = SetupFeaturedForm(instance=featured_event, data=request.POST)

        if form.is_valid():
            featured_event = form.save()

            cost = (featured_event.end_time - featured_event.start_time).days * Money(2, CAD)
            total_price = cost

            for tax in account.taxes():
                total_price = total_price + (cost * tax.tax)

            order = FeaturedEventOrder(
                cost=cost,
                total_price=total_price,
                featured_event=featured_event,
                account=account
            )

            order.save()

            for tax in account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax, cost=cost*tax.tax, tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)
            

            return HttpResponseRedirect(reverse('setup_featured_payment', args=(str(order.id),)))

    return render_to_response('events/setup_featured_event.html', {
            'form': form,
            'featured_events_stats': venue_account_featured_stats
        }, context_instance=RequestContext(request))
Esempio n. 2
0
def deposit_funds_for_campaign(request, campaign_id):
    account = Account.objects.get(user_id=request.user.id)    
    campaign = AdvertisingCampaign.objects.get(id=campaign_id)

    if campaign.account.user != request.user:
        resp = render_to_response('403.html', context_instance=RequestContext(request))
        resp.status_code = 403
        return resp

    form = DepositFundsForCampaignForm()

    if request.method == 'POST':
        form = DepositFundsForCampaignForm(data=request.POST)
        if form.is_valid():
            budget = Decimal(request.POST["order_budget"])
            total_price = budget

            for tax in account.taxes():
                total_price = total_price + (budget * tax.tax)

            order = AdvertisingOrder(
                budget=budget,
                total_price=total_price,
                campaign=campaign,
                account=account
            )


            order.save()

            for tax in account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax, cost=budget*tax.tax, tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)


            return HttpResponseRedirect(reverse('advertising_payment', args=(str(order.id),)))

    return render_to_response('advertising/campaign/deposit_funds.html', {
        "campaign": campaign,
        "form": form
    }, context_instance=RequestContext(request))
Esempio n. 3
0
    def process_order(self):
        cost = self._calculate_cost()
        bonus = Money(Decimal(self.request.POST["bonus"]), CAD)
        cost = cost - bonus

        if cost.amount > 0:
            total_price = cost

            for tax in self.account.taxes():
                total_price = total_price + (cost * tax.tax)

            order = FeaturedEventOrder(
                cost=cost,
                total_price=total_price,
                featured_event=self.featured_event,
                account=self.account
            )

            order.save()

            for tax in self.account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax, cost=cost*tax.tax, tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)

            self.redirect_to_paypal = True

        else:
            order = FeaturedEventOrder(
                cost=cost,
                total_price=cost,
                featured_event=self.featured_event,
                account=self.account,
                status="s"
            )
            order.save()
            FeaturedEvent.objects.filter(id=self.featured_event.id).update(active=True)

        self.order = order
Esempio n. 4
0
    def process_order(self):
        cost = self._calculate_cost()
        bonus = Money(Decimal(self.request.POST["bonus"]), CAD)
        cost = cost - bonus

        if cost.amount > 0:
            total_price = cost

            for tax in self.account.taxes():
                total_price = total_price + (cost * tax.tax)

            order = FeaturedEventOrder(cost=cost,
                                       total_price=total_price,
                                       featured_event=self.featured_event,
                                       account=self.account)

            order.save()

            for tax in self.account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax,
                                                  cost=cost * tax.tax,
                                                  tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)

            self.redirect_to_paypal = True

        else:
            order = FeaturedEventOrder(cost=cost,
                                       total_price=cost,
                                       featured_event=self.featured_event,
                                       account=self.account,
                                       status="s")
            order.save()
            FeaturedEvent.objects.filter(id=self.featured_event.id).update(
                active=True)

        self.order = order
Esempio n. 5
0
    def process_order(self):
        order_budget = Decimal(self.request.POST["budget"]) - Decimal(self.request.POST["bonus"])

        if order_budget:
            total_price = order_budget

            for tax in self.account.taxes():
                total_price = total_price + (order_budget * tax.tax)

            order = AdvertisingOrder(
                budget=order_budget,
                total_price=total_price,
                campaign=self.campaign,
                account=self.account
            )

            order.save()

            for tax in self.account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax, cost=order_budget*tax.tax, tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)

            self.redirect_to_paypal = True

        else:
            order = AdvertisingOrder(
                budget=order_budget,
                total_price=order_budget,
                campaign=self.campaign,
                account=self.account,
                status="s"
            )

            order.save()

        self.order = order
Esempio n. 6
0
    def process_order(self):
        order_budget = Decimal(self.request.POST["budget"]) - Decimal(
            self.request.POST["bonus"])

        if order_budget:
            total_price = order_budget

            for tax in self.account.taxes():
                total_price = total_price + (order_budget * tax.tax)

            order = AdvertisingOrder(budget=order_budget,
                                     total_price=total_price,
                                     campaign=self.campaign,
                                     account=self.account)

            order.save()

            for tax in self.account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax,
                                                  cost=order_budget * tax.tax,
                                                  tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)

            self.redirect_to_paypal = True

        else:
            order = AdvertisingOrder(budget=order_budget,
                                     total_price=order_budget,
                                     campaign=self.campaign,
                                     account=self.account,
                                     status="s")

            order.save()

        self.order = order
Esempio n. 7
0
def setup(request):
    account = Account.objects.get(user_id=request.user.id)
    campaign = AdvertisingCampaign(account=account, venue_account=request.current_venue_account)

    form = PaidAdvertisingSetupForm(account, instance=campaign)

    advertising_types = AdvertisingType.objects.filter(active=True).order_by("id")

    if request.method == 'POST':
        form = PaidAdvertisingSetupForm(account, instance=campaign, data=request.POST, files=request.FILES)
        if form.is_valid():
            advertising_campaign = form.save()

            chosen_advertising_types = get_chosen_advertising_types(campaign, request)
            chosen_advertising_payment_types = get_chosen_advertising_payment_types(campaign, request)
            chosen_advertising_images = get_chosen_advertising_images(campaign, request)

            for advertising_type_id in chosen_advertising_types:
                advertising_type = AdvertisingType.objects.get(id=advertising_type_id)
                advertising = Advertising(
                    ad_type=advertising_type,
                    campaign=advertising_campaign,
                    payment_type=chosen_advertising_payment_types[advertising_type_id],
                    image=chosen_advertising_images[advertising_type_id],
                    cpm_price=advertising_type.cpm_price,
                    cpc_price=advertising_type.cpc_price
                )

                advertising.save()

            budget = Decimal(request.POST["order_budget"])
            total_price = budget

            for tax in account.taxes():
                total_price = total_price + (budget * tax.tax)

            order = AdvertisingOrder(
                budget=budget,
                total_price=total_price,
                campaign=advertising_campaign,
                account=account
            )

            order.save()

            for tax in account.taxes():
                account_tax_cost = AccountTaxCost(account_tax=tax, cost=budget*tax.tax, tax_name=tax.name)
                account_tax_cost.save()
                order.taxes.add(account_tax_cost)


            return HttpResponseRedirect(reverse('advertising_payment', args=(str(order.id),)))

    chosen_advertising_types = get_chosen_advertising_types(campaign, request)
    chosen_advertising_payment_types = get_chosen_advertising_payment_types(campaign, request)
    chosen_advertising_images = get_chosen_advertising_images(campaign, request)

    return render_to_response('advertising/setup.html', {
        "form": form,
        "advertising_types": advertising_types,
        "chosen_advertising_types": chosen_advertising_types,
        "chosen_advertising_payment_types": chosen_advertising_payment_types,
        "chosen_advertising_images": chosen_advertising_images

    }, context_instance=RequestContext(request))