Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
 	client = Ace()
     salesPersonList = client.getSalesPersonList()        
     z=[]
     if salesPersonList != None:
         for x in salesPersonList:
             z.append((x["SalesPersonId"], x["SalesPersonName"]))
     kwargs.setdefault('choices', z)
     super(FormsalesPersonField, self).__init__(*args, **kwargs)
Ejemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     client = Ace()
     salesPersonList = client.getSalesPersonList()
     z = []
     if salesPersonList != None:
         for x in salesPersonList:
             z.append((x["SalesPersonId"], x["SalesPersonName"]))
     kwargs.setdefault('choices', z)
     super(FormsalesPersonField, self).__init__(*args, **kwargs)
Ejemplo n.º 3
0
def network_advertiser_edit(request, id):
    ''' View to allow a Network Admin to edit and update an Advertiser's
        Organization Information '''
    from atrinsic.base.models import ProgramTermSpecialAction, OrganizationContacts, Organization_IO, OrganizationPaymentInfo, Organization, OrganizationCurrency, Currency
    from atrinsic.util.AceFieldLists import Ace
    from forms import NetworkAdvertiserEditForm, NetworkAdvertiserContactEditForm, NetworkAdvertiserOrgIOEditForm, NetworkAdvertiserBillingEditForm, NetworkAdvertiserSettingsEditForm, ProgramTermSpecialActionForm
    advertiser = get_object_or_404(
        request.user.get_profile().admin_assigned_advertisers(), id=id)

    try:
        orgContact = OrganizationContacts.objects.get(organization=advertiser)
    except:
        orgContact = None
    try:
        orgIO = Organization_IO.objects.get(organization=advertiser)
    except:
        orgIO = None

    client = Ace()
    form = None

    special_term, x = ProgramTermSpecialAction.objects.get_or_create(
        organization=advertiser)

    if request.method == 'POST':
        if request.POST.get("formtype", None):
            formType = request.POST.get("formtype")
            if formType == "form":
                form = NetworkAdvertiserEditForm(request.POST,
                                                 request.FILES,
                                                 instance=advertiser)
            elif formType == "formContactEdit":
                form = NetworkAdvertiserContactEditForm(
                    request.POST,
                    instance=OrganizationContacts.objects.get(
                        organization=advertiser))
            elif formType == "formBillingEdit":
                form = NetworkAdvertiserBillingEditForm(
                    request.POST,
                    instance=OrganizationPaymentInfo.objects.get(
                        organization=advertiser))
            elif formType == "formSettingsEdit":
                form = NetworkAdvertiserSettingsEditForm(request.POST,
                                                         instance=advertiser)
            elif formType == "formTermsEdit":
                form = ProgramTermSpecialActionForm(request.POST,
                                                    instance=special_term)
            elif formType == "formIOStatusUpdate":
                form = None
                if orgIO != None:
                    args = {}
                    args["ioId"] = orgIO.ace_ioid
                    args["statusId"] = APPROVED_BY_SALES_MANAGER
                    args["spId"] = request.POST.get("salesperson")
                    updateIOStatus(advertiser, args)
            elif formType == "formIOFeeSettingsEdit":
                form = NetworkAdvertiserOrgIOEditForm(request.POST,
                                                      instance=advertiser)
                if orgIO != None:
                    if form.is_valid():
                        orgIO.transaction_fee_type = request.POST.get(
                            "transaction_fee_type")
                        orgIO.transaction_fee_amount = request.POST.get(
                            "transaction_fee_amount")
                        orgIO.save()
                    else:
                        return HttpResponseRedirect(
                            '/network/advertiser/edit/%d/?error=1' % int(id))

                    form = None

                    if orgIO.salesrep == 0 or orgIO.salesrep == None:
                        orgIO.salesrep = request.POST.get("salesperson")
                        orgIO.save()
                    args = {}
                    args["ioId"] = orgIO.ace_ioid
                    args["spId"] = request.POST.get("salesperson")
                    for x in request.POST:
                        '''
                            Since the intitial Placement fees were pulled dynamically, 
                            we need to check based on checkboxes being "on" as unchecked boxes do not post.
                        '''
                        if request.POST.get(x) == "on":
                            args["feeId"] = x.replace("idplacement_", "")
                            args["feeAmount"] = request.POST.get(x + "amt")
                            createFee(advertiser, args)
                        '''
                            When placement fees were intially pulled, added a hidden field to keep track
                            of which fees were already chosen. Compare initial values(tracker), against
                            whther or not its corresponding checkbox is "on".
                            If theres a discrepency, ie. Was on, now off, deleteFee                            
                        '''
                        if x.find("pftracker_") > -1:
                            args["feeId"] = x.replace("pftracker_", "")
                            if request.POST.get(x) == "1" and request.POST.get(
                                    "idplacement_" +
                                    str(args["feeId"])) == None:
                                deleteFee(advertiser, args)

            if form != None and form.is_valid():
                if formType == "formContactEdit":
                    if orgContact != None:
                        orgContact.firstname = form.cleaned_data.get(
                            'firstname')
                        orgContact.lastname = form.cleaned_data.get('lastname')
                        orgContact.email = form.cleaned_data.get('email')
                        orgContact.phone = form.cleaned_data.get('phone')
                        orgContact.fax = form.cleaned_data.get('fax')
                        orgContact.save()
                else:
                    form.save()
                    if formType == "form":
                        try:
                            currency_obj = OrganizationCurrency.objects.get(
                                advertiser=advertiser)
                            currency_obj.currency = Currency.objects.get(
                                order=form.cleaned_data.get('currency'))
                            currency_obj.save()
                        except:
                            currency_obj = OrganizationCurrency.objects.create(
                                advertiser=advertiser,
                                currency=Currency.objects.get(
                                    order=form.cleaned_data.get('currency')))

            return HttpResponseRedirect('/network/advertiser/settings/')
        else:
            #print form.errors #this is crashing when  formType == "formIOStatusUpdate":
            return HttpResponseRedirect('/network/advertiser/edit/%d/' %
                                        int(id))

    else:
        #Obtain the Currency used by the advertiser and pass it to the form:
        cur_inits = {}

        cur_obj = OrganizationCurrency.objects.filter(advertiser=advertiser)
        curID = 0
        if cur_obj.count() != 0:
            curID = cur_obj[0].currency.order
        cur_inits = {
            'currency': curID,
        }
        form = NetworkAdvertiserEditForm(instance=advertiser,
                                         initial=cur_inits)

        inits = {}
        if orgContact != None:
            inits = {
                'firstname': orgContact.firstname,
                'lastname': orgContact.lastname,
                'email': orgContact.email,
                'phone': orgContact.phone,
                'fax': orgContact.fax,
            }
        else:
            inits = {
                'firstname': '',
                'lastname': '',
                'email': '',
                'phone': '',
                'fax': '',
            }

        paymentInfo, t = OrganizationPaymentInfo.objects.get_or_create(
            organization=Organization.objects.get(pk=id))
        formContactEdit = NetworkAdvertiserContactEditForm(instance=advertiser,
                                                           initial=inits)
        formBillingEdit = NetworkAdvertiserBillingEditForm(
            instance=paymentInfo)
        formSettingsEdit = NetworkAdvertiserSettingsEditForm(
            instance=advertiser)
        formTermsEdit = ProgramTermSpecialActionForm(instance=special_term)
        if orgIO != None:
            formOrgIOEdit = NetworkAdvertiserOrgIOEditForm(instance=orgIO)
        else:
            formOrgIOEdit = None

        chosenSalesPerson = 0

        if orgIO != None:
            showIOFees = True
            args = {}
            args["ioId"] = orgIO.ace_ioid
            placementFeesList = getFees(advertiser)
            try:
                io = getIO(advertiser, args)
                ioStatus = io['StatusName']
            except:
                ioStatus = "Unavailable"

            if ioStatus != "Pending Sales Approval":
                ioStatus = False

            if orgIO.salesrep != None and orgIO.salesrep != 0:
                chosenSalesPerson = orgIO.salesrep

        else:
            showIOFees = False
            placementFeesList = None
            ioStatus = False

    return AQ_render_to_response(
        request,
        'network/advertiser-edit.html',
        {
            'advertiser': advertiser,
            'form': form,
            'formContactEdit': formContactEdit,
            'formBillingEdit': formBillingEdit,
            'formTermsEdit': formTermsEdit,
            'formSettingsEdit': formSettingsEdit,
            'formOrgIOEdit': formOrgIOEdit,
            'placementFeesList': placementFeesList,
            'showIOFees': showIOFees,
            'SalesPersonList': client.getSalesPersonList(),
            'chosenSalesPerson': chosenSalesPerson,
            #'arrIOs' : searchIOs(),
            'ioStatus': ioStatus,
        },
        context_instance=RequestContext(request))
Ejemplo n.º 4
0
def network_advertiser_edit(request, id):
    ''' View to allow a Network Admin to edit and update an Advertiser's
        Organization Information '''    
    from atrinsic.base.models import ProgramTermSpecialAction,OrganizationContacts, Organization_IO, OrganizationPaymentInfo, Organization, OrganizationCurrency, Currency
    from atrinsic.util.AceFieldLists import Ace
    from forms import NetworkAdvertiserEditForm,NetworkAdvertiserContactEditForm,NetworkAdvertiserOrgIOEditForm,NetworkAdvertiserBillingEditForm,NetworkAdvertiserSettingsEditForm,ProgramTermSpecialActionForm
    advertiser = get_object_or_404(request.user.get_profile().admin_assigned_advertisers(), id=id)
    
    try:
        orgContact = OrganizationContacts.objects.get(organization=advertiser)
    except:
        orgContact = None
    try:
        orgIO = Organization_IO.objects.get(organization=advertiser)
    except:
        orgIO = None
    
    client = Ace()
    form = None
    
    special_term,x = ProgramTermSpecialAction.objects.get_or_create(organization = advertiser)
        
    if request.method == 'POST':
        if request.POST.get("formtype",None):
            formType = request.POST.get("formtype")
            if formType == "form":
                form = NetworkAdvertiserEditForm(request.POST, request.FILES, instance=advertiser)
            elif formType == "formContactEdit":
                form = NetworkAdvertiserContactEditForm(request.POST, instance=OrganizationContacts.objects.get(organization=advertiser))
            elif formType == "formBillingEdit":
                form = NetworkAdvertiserBillingEditForm(request.POST, instance=OrganizationPaymentInfo.objects.get(organization=advertiser))
            elif formType == "formSettingsEdit":
                form = NetworkAdvertiserSettingsEditForm(request.POST, instance=advertiser)
            elif formType == "formTermsEdit":
                form = ProgramTermSpecialActionForm(request.POST, instance=special_term)
            elif formType == "formIOStatusUpdate":
                form = None
                if orgIO != None:
                    args = {}
                    args["ioId"] = orgIO.ace_ioid  
                    args["statusId"] = APPROVED_BY_SALES_MANAGER  
                    args["spId"] = request.POST.get("salesperson")  
                    updateIOStatus(advertiser,args)
            elif formType == "formIOFeeSettingsEdit":  
                form = NetworkAdvertiserOrgIOEditForm(request.POST, instance=advertiser)
                if orgIO != None:
                    if form.is_valid():
                        orgIO.transaction_fee_type = request.POST.get("transaction_fee_type")
                        orgIO.transaction_fee_amount = request.POST.get("transaction_fee_amount")
                        orgIO.save()
                    else:
                        return HttpResponseRedirect('/network/advertiser/edit/%d/?error=1' % int(id))
                        
                    form = None
                    
                    if orgIO.salesrep == 0 or orgIO.salesrep == None:
                        orgIO.salesrep = request.POST.get("salesperson")
                        orgIO.save()
                    args = {}
                    args["ioId"] = orgIO.ace_ioid  
                    args["spId"] = request.POST.get("salesperson")  
                    for x in request.POST:
                        '''
                            Since the intitial Placement fees were pulled dynamically, 
                            we need to check based on checkboxes being "on" as unchecked boxes do not post.
                        '''
                        if request.POST.get(x) == "on":
                            args["feeId"] = x.replace("idplacement_", "")
                            args["feeAmount"] = request.POST.get(x + "amt")
                            createFee(advertiser,args)
                        
                        '''
                            When placement fees were intially pulled, added a hidden field to keep track
                            of which fees were already chosen. Compare initial values(tracker), against
                            whther or not its corresponding checkbox is "on".
                            If theres a discrepency, ie. Was on, now off, deleteFee                            
                        '''
                        if x.find("pftracker_") > -1:
                            args["feeId"] = x.replace("pftracker_", "")
                            if request.POST.get(x) == "1" and request.POST.get("idplacement_" + str(args["feeId"])) == None:
                                deleteFee(advertiser,args)
            
            if form != None and form.is_valid():
                if formType == "formContactEdit":
                    if orgContact != None:
                        orgContact.firstname = form.cleaned_data.get('firstname')
                        orgContact.lastname = form.cleaned_data.get('lastname')
                        orgContact.email = form.cleaned_data.get('email')
                        orgContact.phone = form.cleaned_data.get('phone') 
                        orgContact.fax =  form.cleaned_data.get('fax')
                        orgContact.save()
                else:
                    form.save()
                    if formType == "form":
                        try:
                            currency_obj = OrganizationCurrency.objects.get(advertiser = advertiser)
                            currency_obj.currency = Currency.objects.get(order=form.cleaned_data.get('currency'))
                            currency_obj.save()
                        except:
                            currency_obj = OrganizationCurrency.objects.create(advertiser=advertiser, currency = Currency.objects.get(order=form.cleaned_data.get('currency')))
               
            return HttpResponseRedirect('/network/advertiser/settings/')
        else:
            #print form.errors #this is crashing when  formType == "formIOStatusUpdate":
            return HttpResponseRedirect('/network/advertiser/edit/%d/' % int(id))
        
    else:
        #Obtain the Currency used by the advertiser and pass it to the form:
        cur_inits = {}
        
        cur_obj = OrganizationCurrency.objects.filter(advertiser=advertiser)
        curID = 0
        if cur_obj.count() != 0:
            curID = cur_obj[0].currency.order    		
        cur_inits = {'currency':curID,}
        form = NetworkAdvertiserEditForm(instance=advertiser,initial=cur_inits)
        
        inits = {}
        if orgContact != None:
            inits = {'firstname':orgContact.firstname, 
                     'lastname':orgContact.lastname,
                     'email':orgContact.email, 
                     'phone':orgContact.phone, 
                     'fax':orgContact.fax,}
        else:
            inits = {'firstname':'', 
                     'lastname':'',
                     'email':'', 
                     'phone':'', 
                     'fax':'',}
        
        paymentInfo,t = OrganizationPaymentInfo.objects.get_or_create(organization = Organization.objects.get(pk=id))
        formContactEdit = NetworkAdvertiserContactEditForm(instance=advertiser,initial=inits)
        formBillingEdit = NetworkAdvertiserBillingEditForm(instance=paymentInfo)
        formSettingsEdit = NetworkAdvertiserSettingsEditForm(instance=advertiser)
        formTermsEdit = ProgramTermSpecialActionForm(instance=special_term)
        if orgIO != None:
            formOrgIOEdit = NetworkAdvertiserOrgIOEditForm(instance=orgIO)
        else:
            formOrgIOEdit = None
            
        chosenSalesPerson = 0

        if orgIO != None:
            showIOFees = True
            args = {}
            args["ioId"] = orgIO.ace_ioid            
            placementFeesList = getFees(advertiser)
            try:
                io = getIO(advertiser,args)
                ioStatus = io['StatusName']
            except:
                ioStatus = "Unavailable"
                
            if ioStatus != "Pending Sales Approval":
                ioStatus = False
            
            if orgIO.salesrep != None and orgIO.salesrep != 0:
                chosenSalesPerson = orgIO.salesrep           
            
        else:
            showIOFees = False
            placementFeesList = None
            ioStatus = False        
    
    return AQ_render_to_response(request, 'network/advertiser-edit.html', {
            'advertiser' : advertiser,
            'form' : form,
            'formContactEdit' : formContactEdit,
            'formBillingEdit' : formBillingEdit,
            'formTermsEdit' : formTermsEdit,
            'formSettingsEdit' : formSettingsEdit,
            'formOrgIOEdit' : formOrgIOEdit,
            'placementFeesList' : placementFeesList,
            'showIOFees' : showIOFees,
            'SalesPersonList' : client.getSalesPersonList(),
            'chosenSalesPerson' : chosenSalesPerson,
            #'arrIOs' : searchIOs(),
            'ioStatus' : ioStatus,
        }, context_instance=RequestContext(request))