Example #1
0
def admin_advertising_setup(request):
    account = Account.objects.get(user_id=request.user.id)
    campaign = AdvertisingCampaign(account=account, free=True)
    form = AdvertisingSetupForm(account, instance=campaign)

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

    if request.method == 'POST':
        form = AdvertisingSetupForm(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,
                    review_status="ACCEPTED")

                advertising.save()

            return HttpResponseRedirect(reverse('admin_advertising'))

    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(
        'cf-admin/ads/admin-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))
Example #2
0
def setup(request):
    account = Account.objects.get(user_id=request.user.id)
    campaign = AdvertisingCampaign(account=account,
                                   venue_account=request.current_venue_account)

    form = PaypalSetupForm(account,
                           instance=campaign,
                           initial={
                               "bonus": (0, CAD),
                               "budget": (0, CAD)
                           })

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

    if request.method == 'POST':
        form = PaypalSetupForm(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()

            return process_payment_for_campaign(account, advertising_campaign,
                                                request)

    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,
        "account": account
    },
                              context_instance=RequestContext(request))