Esempio n. 1
0
def publisher_settings_pixel_edit(request, id):
    ''' View to allow a Publisher to edit a WebSite '''
    from forms import PiggybackForm
    from atrinsic.base.models import Action
    pbPixel = get_object_or_404(request.organization.piggybackpixel_set, id=id)

    if request.method == 'POST':
        form = PiggybackForm(request.organization, request.POST)
        if form.is_valid():

            ##################
            apeClient = Ape()
            ape_redirect_id = None
            getActions = Action.objects.filter(
                advertiser=form.cleaned_data['advertiser']).order_by('id')

            if getActions.count() == 0:
                # Do not create Pixel
                pass
            else:
                #Use RedirectID from Oldest Action(order_by('id')) and create actions under that RedirectID
                ape_redirect_id = getActions[0].ape_redirect_id

            # If script pixel, then we must create a piggy back
            # for both the JS Include(jsinclude), as well as the JS Code(content)
            if form.cleaned_data[
                    'pixel_type'] == PIXEL_TYPE_SCRIPT and pbPixel.ape_include_pixel_id != 0:
                success, updatePixel = apeClient.execute_piggyback_update(
                    request, ape_redirect_id, pbPixel.ape_include_pixel_id,
                    form.cleaned_data['jsinclude'])

            #Call APE and create Piggyback Pixel with redirect determined above.
            success, createPixel = apeClient.execute_piggyback_update(
                request, ape_redirect_id, pbPixel.ape_content_pixel_id,
                form.cleaned_data['content'])

            pbPixel.advertiser = form.cleaned_data['advertiser']
            pbPixel.pixel_type = form.cleaned_data['pixel_type']
            pbPixel.jsinclude = form.cleaned_data['jsinclude']
            pbPixel.content = form.cleaned_data['content']

            pbPixel.save()

            return HttpResponseRedirect(reverse('publisher_piggyback_pixel'))
    else:
        inits = {
            'advertiser': pbPixel.advertiser.pk,
            'pixel_type': pbPixel.pixel_type,
            'jsinclude': pbPixel.jsinclude,
            'content': pbPixel.content,
        }
        form = PiggybackForm(request.organization, initial=inits)

    return AQ_render_to_response(request,
                                 'publisher/settings/pixel-edit.html', {
                                     'form': form,
                                     'pixel': pbPixel
                                 },
                                 context_instance=RequestContext(request))
Esempio n. 2
0
def publisher_settings_pixel_add(request):
    ''' View to allow a Publisher the ability to add a WebSite '''
    from atrinsic.base.models import Action, PiggybackPixel
    from forms import PiggybackForm

    if request.method == 'POST':
        form = PiggybackForm(request.organization, request.POST)
        if form.is_valid():
            ##################
            apeClient = Ape()
            ape_redirect_id = None
            getActions = Action.objects.filter(
                advertiser=form.cleaned_data['advertiser']).order_by('id')

            if getActions.count() == 0:
                # Do not create Pixel
                pass
            else:
                #Use RedirectID from Oldest Action(order_by('id')) and create actions under that RedirectID
                ape_redirect_id = getActions[0].ape_redirect_id

            # If script pixel, then we must create a piggy back
            # for both the JS Include(jsinclude), as well as the JS Code(content)
            includePixelID = 0
            if form.cleaned_data[
                    'pixel_type'] == PIXEL_TYPE_SCRIPT and form.cleaned_data[
                        'jsinclude'] != "":
                success, createPixel = apeClient.execute_piggyback_create(
                    request, ape_redirect_id, PIXEL_TYPE_IFRAME,
                    form.cleaned_data['jsinclude'])
                if success:
                    includePixelID = createPixel['pixel_id']
            #Call APE and create Piggyback Pixel with redirect determined above.
            success, createPixel = apeClient.execute_piggyback_create(
                request, ape_redirect_id, form.cleaned_data['pixel_type'],
                form.cleaned_data['content'])
            if success:
                PiggybackPixel.objects.create(
                    publisher=request.organization,
                    advertiser=form.cleaned_data['advertiser'],
                    pixel_type=form.cleaned_data['pixel_type'],
                    jsinclude=form.cleaned_data['jsinclude'],
                    ape_content_pixel_id=createPixel['pixel_id'],
                    ape_include_pixel_id=includePixelID,
                    content=form.cleaned_data['content'])

            return HttpResponseRedirect(reverse('publisher_settings_websites'))
    else:
        form = PiggybackForm(request.organization)

    return AQ_render_to_response(request,
                                 'publisher/settings/pixel-add.html', {
                                     'form': form,
                                 },
                                 context_instance=RequestContext(request))
Esempio n. 3
0
def publisher_settings_pixel_edit(request, id):
    ''' View to allow a Publisher to edit a WebSite '''
    from forms import PiggybackForm    
    from atrinsic.base.models import Action
    pbPixel = get_object_or_404(request.organization.piggybackpixel_set, id=id)

    
    if request.method == 'POST':
        form = PiggybackForm(request.organization, request.POST)
        if form.is_valid():
            
            ##################
            apeClient = Ape()
            ape_redirect_id = None   
            getActions = Action.objects.filter(advertiser=form.cleaned_data['advertiser']).order_by('id')
            
            if getActions.count() == 0:
                # Do not create Pixel
                pass
            else:
                #Use RedirectID from Oldest Action(order_by('id')) and create actions under that RedirectID
                ape_redirect_id = getActions[0].ape_redirect_id
            
            # If script pixel, then we must create a piggy back 
            # for both the JS Include(jsinclude), as well as the JS Code(content)
            if form.cleaned_data['pixel_type'] == PIXEL_TYPE_SCRIPT and pbPixel.ape_include_pixel_id != 0:                
                success, updatePixel = apeClient.execute_piggyback_update(request,ape_redirect_id,pbPixel.ape_include_pixel_id,form.cleaned_data['jsinclude']) 
                
            #Call APE and create Piggyback Pixel with redirect determined above.
            success, createPixel = apeClient.execute_piggyback_update(request,ape_redirect_id,pbPixel.ape_content_pixel_id,form.cleaned_data['content'])       

                
            
            pbPixel.advertiser = form.cleaned_data['advertiser']
            pbPixel.pixel_type = form.cleaned_data['pixel_type']
            pbPixel.jsinclude=form.cleaned_data['jsinclude']
            pbPixel.content = form.cleaned_data['content']                    
            
            pbPixel.save()

            return HttpResponseRedirect(reverse('publisher_piggyback_pixel'))
    else:
        inits = {
            'advertiser':pbPixel.advertiser.pk,
            'pixel_type':pbPixel.pixel_type,
            'jsinclude':pbPixel.jsinclude,
            'content':pbPixel.content,
        }
        form = PiggybackForm(request.organization, initial=inits)

    return AQ_render_to_response(request, 'publisher/settings/pixel-edit.html', {
        'form': form,
        'pixel':pbPixel
        }, context_instance=RequestContext(request))
Esempio n. 4
0
def publisher_settings_pixel_add(request):
    ''' View to allow a Publisher the ability to add a WebSite '''
    from atrinsic.base.models import Action, PiggybackPixel
    from forms import PiggybackForm
    
    if request.method == 'POST':
        form = PiggybackForm(request.organization, request.POST)
        if form.is_valid():         
            ##################
            apeClient = Ape()
            ape_redirect_id = None   
            getActions = Action.objects.filter(advertiser=form.cleaned_data['advertiser']).order_by('id')
            
            if getActions.count() == 0:
                # Do not create Pixel
                pass
            else:
                #Use RedirectID from Oldest Action(order_by('id')) and create actions under that RedirectID
                ape_redirect_id = getActions[0].ape_redirect_id
            
            # If script pixel, then we must create a piggy back 
            # for both the JS Include(jsinclude), as well as the JS Code(content)
            includePixelID = 0
            if form.cleaned_data['pixel_type'] == PIXEL_TYPE_SCRIPT and form.cleaned_data['jsinclude'] != "":                
                success, createPixel = apeClient.execute_piggyback_create(request,ape_redirect_id,PIXEL_TYPE_IFRAME,form.cleaned_data['jsinclude']) 
                if success:
                    includePixelID = createPixel['pixel_id']
            #Call APE and create Piggyback Pixel with redirect determined above.
            success, createPixel = apeClient.execute_piggyback_create(request,ape_redirect_id,form.cleaned_data['pixel_type'],form.cleaned_data['content'])       
            if success:
                PiggybackPixel.objects.create(publisher=request.organization, advertiser=form.cleaned_data['advertiser'],
                        pixel_type=form.cleaned_data['pixel_type'], jsinclude=form.cleaned_data['jsinclude'], ape_content_pixel_id = createPixel['pixel_id'], ape_include_pixel_id = includePixelID, content=form.cleaned_data['content'])

            return HttpResponseRedirect(reverse('publisher_settings_websites'))
    else:
        form = PiggybackForm(request.organization)

    return AQ_render_to_response(request, 'publisher/settings/pixel-add.html', {
        'form': form,
        }, context_instance=RequestContext(request))