示例#1
0
def publisher_settings_websites_add(request):
    ''' View to allow a Publisher the ability to add a WebSite '''
    from atrinsic.base.models import Website
    from forms import WebsiteForm

    if request.method == 'POST':
        form = WebsiteForm(request.POST)
        if form.is_valid():
            Website.objects.create(
                publisher=request.organization,
                url=form.cleaned_data['url'],
                desc=form.cleaned_data['desc'],
                promo_method=form.cleaned_data['promo_method'],
                vertical=form.cleaned_data['vertical'],
                is_incentive=form.cleaned_data['is_incentive'],
                incentive_desc=form.cleaned_data['incentive_desc'])

            return HttpResponseRedirect(reverse('publisher_settings_websites'))
    else:
        form = WebsiteForm()

    return AQ_render_to_response(request,
                                 'publisher/settings/websites-add.html', {
                                     'form': form,
                                 },
                                 context_instance=RequestContext(request))
示例#2
0
def websites(request):
    plan, has_only_expired_plans = Plan.objects.get_current_plan_for_user(
        request.user)
    if not plan or not plan.is_pro():
        raise Http404("You don't have the Pro plan.")
    cluster, created = WebsiteCluster.objects.get_or_create(
        creator=request.user)
    profile = ClientProfile.objects.get(user=request.user)
    too_many_websites = False
    if cluster.website_set.count() >= settings.MAX_NUMBER_OF_WEBSITES_ON_PRO:
        too_many_websites = True
    if created:
        default_website = website_from_profile(profile, cluster)
    if request.method == "POST":
        form = WebsiteForm(request.POST, request.FILES)
        if form.is_valid():
            # create the website
            website = Website(
                website_url=form.cleaned_data.get('website_url'),
                cluster=cluster,
                website_name=form.cleaned_data.get('website_name'))
            website.save()
            # create the website icon
            website_icon = WebsiteIcon(website=website,
                                       image=form.cleaned_data.get('icon'))
            website_icon.save()
            # associate a push package
            package_manager = PushPackageManager()
            package = package_manager.get_push_package(profile)
            if package:
                package.generate_zip(
                    website.website_name,
                    website.website_url,
                    website_icon.image128_2x.path,
                    website_icon.image128.path,
                    website_icon.image32_2x.path,
                    website_icon.image32.path,
                    website_icon.image16_2x.path,
                    website_icon.image16.path,
                )
                website.account_key = package.identifier
                website.save()
                package.used = True
                package.save()
            return HttpResponseRedirect(reverse('websites'))
    else:
        form = WebsiteForm()
    return render_to_response(
        'clients/websites.html', {
            "form": form,
            "cluster": cluster,
            'plan': plan,
            'too_many_websites': too_many_websites,
        }, RequestContext(request))
示例#3
0
def publisher_settings_websites_edit(request, id):
    ''' View to allow a Publisher to edit a WebSite '''
    from forms import WebsiteForm

    website = get_object_or_404(request.organization.website_set, id=id)

    if request.method == 'POST':
        form = WebsiteForm(request.POST, instance=website)
        if form.is_valid():
            website.url = form.cleaned_data.get('url', None)
            website.desc = form.cleaned_data.get('desc', None)
            website.promo_method = form.cleaned_data.get('promo_method', None)
            website.vertical = form.cleaned_data.get('vertical', None)
            website.is_incentive = form.cleaned_data.get('is_incentive', None)
            website.incentive_desc = form.cleaned_data.get(
                'incentive_desc', None)
            website.is_default = form.cleaned_data.get('is_default', False)
            website.save()

            return HttpResponseRedirect(reverse('publisher_settings_websites'))
    else:
        if (website.promo_method == None):
            promoPKFix = None
        else:
            promoPKFix = website.promo_method.pk
        if (website.vertical == None):
            vertFix = None
        else:
            vertFix = website.vertical.pk
        inits = {
            'url': website.url,
            'desc': website.desc,
            'promo_method': promoPKFix,
            'vertical': vertFix,
            'is_incentive': website.is_incentive,
            'incentive_desc': website.incentive_desc,
            'is_default': website.is_default,
        }
        form = WebsiteForm(initial=inits)

    return AQ_render_to_response(request,
                                 'publisher/settings/websites-edit.html', {
                                     'form': form,
                                     'website': website
                                 },
                                 context_instance=RequestContext(request))
示例#4
0
def publisher_settings_websites_edit(request, id):
    ''' View to allow a Publisher to edit a WebSite '''
    from forms import WebsiteForm
    
    website = get_object_or_404(request.organization.website_set, id=id)

    
    if request.method == 'POST':
        form = WebsiteForm(request.POST, instance=website)
        if form.is_valid():
            website.url = form.cleaned_data.get('url', None)
            website.desc = form.cleaned_data.get('desc', None)
            website.promo_method = form.cleaned_data.get('promo_method', None)
            website.vertical = form.cleaned_data.get('vertical', None)
            website.is_incentive = form.cleaned_data.get('is_incentive', None)
            website.incentive_desc = form.cleaned_data.get('incentive_desc', None)
            website.is_default = form.cleaned_data.get('is_default', False)
            website.save()

            return HttpResponseRedirect(reverse('publisher_settings_websites'))
    else:
        if(website.promo_method == None):
            promoPKFix = None
        else:
            promoPKFix = website.promo_method.pk
        if(website.vertical == None):
            vertFix = None
        else:
            vertFix = website.vertical.pk
        inits = {
            'url':website.url,
            'desc':website.desc,
            'promo_method':promoPKFix,
            'vertical':vertFix,
            'is_incentive':website.is_incentive,
            'incentive_desc':website.incentive_desc,
            'is_default':website.is_default,
        }
        form = WebsiteForm(initial=inits)

    return AQ_render_to_response(request, 'publisher/settings/websites-edit.html', {
        'form': form,
        'website':website
        }, context_instance=RequestContext(request))
示例#5
0
def publisher_settings_websites_add(request):
    ''' View to allow a Publisher the ability to add a WebSite '''
    from atrinsic.base.models import Website
    from forms import WebsiteForm
    
    if request.method == 'POST':
        form = WebsiteForm(request.POST)
        if form.is_valid():
            Website.objects.create(publisher=request.organization, url=form.cleaned_data['url'],
                    desc=form.cleaned_data['desc'], promo_method=form.cleaned_data['promo_method'],
                    vertical=form.cleaned_data['vertical'], is_incentive=form.cleaned_data['is_incentive'],
                    incentive_desc=form.cleaned_data['incentive_desc'])

            return HttpResponseRedirect(reverse('publisher_settings_websites'))
    else:
        form = WebsiteForm()

    return AQ_render_to_response(request, 'publisher/settings/websites-add.html', {
        'form': form,
        }, context_instance=RequestContext(request))
示例#6
0
def signup_publisher_step4(request):
    ''' Fourth step of publisher signup process, confirms the email'''
    from forms import PublisherSignupForm3,WebsiteForm,PaymentInfoForm,ContactInfoForm, ContactInfoFormSmallest
    from atrinsic.util.user import generate_username
    from atrinsic.base.models import PublisherApplication,Organization,Website,OrganizationContacts,OrganizationPaymentInfo,User,UserProfile

    if request.method == "GET":
        if request.GET.get("id",None) and request.GET.get("key",None):
            if PublisherApplication.objects.filter(validation_code=request.GET['key'],id=request.GET['id']).count() > 0:
                app = PublisherApplication.objects.filter(validation_code=request.GET['key'],id=request.GET['id'])[0]
                form = PublisherSignupForm3(False)
                website_form = WebsiteForm()
                payment_form = PaymentInfoForm()   
                print app.email
                inits = { 'payeename':'', 
                          'firstname':'', 
                          'lastname':'', 
                          'phone':'', 
                          'email': app.email, }
                formCI = ContactInfoForm(initial=inits)
                inits = { 'xs_firstname':'', 
                          'xs_lastname':'', 
                          'xs_email': app.email, }
                formCIxs = ContactInfoFormSmallest(initial=inits)
                key = request.GET['key']
                appid = request.GET['id']
                
                return AQ_render_to_response(request, 'signup/publisher_newStep.html', {
                 'payment_form':payment_form,
                 'formCI' : formCI,
                 'formCIxs' : formCIxs,
                 'website_form':website_form,
                 'form' : form,
                 'key' : key,
                 'appid' : appid,
                    }, context_instance=RequestContext(request))
            else:
                #application could not be found
                return AQ_render_to_response(request, 'signup/appnotfound.html', {
                    }, context_instance=RequestContext(request))        
        else:
            return AQ_render_to_response(request, 'signup/publisher_step4.html', {
                    }, context_instance=RequestContext(request))        
    else:

        form = PublisherSignupForm3(False,request.POST)
        website_form = WebsiteForm(request.POST)
        payment_form = PaymentInfoForm(request.POST)
        formCI = ContactInfoForm(request.POST)
        formCIxs = ContactInfoFormSmallest(request.POST)
        key = request.POST['key']
        appid = request.POST['appid']
        
        if form.is_valid() and website_form.is_valid() and  payment_form.is_valid():
            useSmallContactForm = True
            if payment_form.cleaned_data['payment_method'] == PAYMENT_CHECK:
                if formCI.is_valid():
                    useSmallContactForm = False
                else:
                    #1 or more forms are not valid
                    return AQ_render_to_response(request, 'signup/publisher_newStep.html', {
                         'payment_form':payment_form,
                         'formCI' : formCI,
                         'formCIxs' : formCIxs,
                         'website_form':website_form,
                         'form' : form,
                         'key' : key,
                         'appid' : appid,
                            }, context_instance=RequestContext(request))
            else:
                if formCIxs.is_valid():
                    useSmallContactForm = True
                else:
                    #1 or more forms are not valid
                    return AQ_render_to_response(request, 'signup/publisher_newStep.html', {
                         'payment_form':payment_form,
                         'formCI' : formCI,
                         'formCIxs' : formCIxs,
                         'website_form':website_form,
                         'form' : form,
                         'key' : key,
                         'appid' : appid,
                            }, context_instance=RequestContext(request))
            #create Organization
           
            org = Organization.objects.create(org_type=ORGTYPE_PUBLISHER, status=ORGSTATUS_UNAPPROVED)

            org.company_name = form.cleaned_data['company_name']
            org.address = form.cleaned_data['pub_address']
            org.address2 = form.cleaned_data['pub_address2']
            org.city = form.cleaned_data['pub_city']
            org.state = form.cleaned_data['pub_state']
            org.zipcode = form.cleaned_data['pub_zipcode']
            org.country = form.cleaned_data['pub_country']
            if str(website_form.cleaned_data['vertical']) == "Adult":
                org.is_adult = 1
            org.save()
            
            if useSmallContactForm:     
                org_contact = OrganizationContacts.objects.create(organization=org, firstname=formCIxs.cleaned_data['xs_firstname'],lastname=formCIxs.cleaned_data['xs_lastname'],email=formCIxs.cleaned_data['xs_email'])
                org_contact.save()       
            else:        
                org_contact = OrganizationContacts.objects.create(organization=org, **formCI.cleaned_data)
                org_contact.save()
                address = formCI.cleaned_data['address']        
            app = PublisherApplication.objects.filter(validation_code=key,id=appid)[0]
            
            try:
                term_log = Terms_Accepted_Log.objects.get(organization_id=app)
                term_log.organization_id = org.id
                term_log.save()
            except:
                pass
            
            address = ""                
            website = Website.objects.create(publisher = org, is_default = True, **website_form.cleaned_data)
            website.save()
            org_payment = OrganizationPaymentInfo.objects.create(organization=org, **payment_form.cleaned_data)
            org_payment.save()
            
            first_name = app.first_name
            last_name = app.last_name
            password = app.password
            
            if useSmallContactForm:     
                email=formCIxs.cleaned_data['xs_email']
            else:      
                email=formCI.cleaned_data['email']
                            
            if payment_form.cleaned_data['payment_method'] == PAYMENT_CHECK:
                payee_name = formCI.cleaned_data['payeename']
                first_name = formCI.cleaned_data['firstname']
                last_name = formCI.cleaned_data['lastname']
            
            
            # Create User, Set Password, Map to Organization            
            u = User.objects.create(first_name=first_name,last_name=last_name,password=password,email=email, username=generate_username(email))
            up = UserProfile.objects.create(user=u)
            up.organizations.add(org)
            
            # Assign all ADMINLEVEL_ADMINISTRATOR to this
            for up in UserProfile.objects.filter(admin_level=ADMINLEVEL_ADMINISTRATOR):
                up.admin_assigned_organizations.add(org)
                up.save()
               
            #Emails
            from django.core.mail import EmailMultiAlternatives
            print "Sending mail"
            msg = EmailMultiAlternatives("Atrinsic Affiliate Network  Publisher Application", u"""
Dear """+first_name[0:1].upper()+first_name[1:]+""" """+last_name[0:1].upper()+last_name[1:]+""",

Thank you for applying to become a publisher on the Atrinsic Affiliate Network.

Your application has been placed in our queue and will be reviewed as quickly as possible.  You will be contacted shortly by a member of the Atrinsic Affiliate Network Publisher team to verify some information on your application.
If, at any time, you have questions or concerns, please contact us at [email protected].

We receive a large volume of applications each day and your application will be processed in the order in which it was received.


Thank you for your interest in working with Atrinsic Affiliate Network!

Sincerely,

The Atrinsic Affiliate Network Publisher Team

""","*****@*****.**",[email])

            msg.send()
            
            themessage = u"""Dear Admin! this is a glorious day, a new publisher has join our ranks.
            Name: """+first_name[0:1].upper()+first_name[1:]+""" """+last_name[0:1].upper()+last_name[1:]
            themessage += """
            Address: """+address+"""
            Email: """+email+"""
            Website URL: """+website_form.cleaned_data['url']+"""
            
            please review this application,
            
            Sincerely,
            
            The Atrinsic Affiliate Network Robot that sends email"""
                
            msg2 = EmailMultiAlternatives("Atrinsic Affiliate Network Publisher Application",themessage,"*****@*****.**",['*****@*****.**'])
            msg2.send()    
                     
            return AQ_render_to_response(request, 'signup/publisher_complete.html', {
        }, context_instance=RequestContext(request))
        
        else:
            #1 or more forms are not valid
            return AQ_render_to_response(request, 'signup/publisher_newStep.html', {
                 'payment_form':payment_form,
                 'formCI' : formCI,
                 'formCIxs' : formCIxs,
                 'website_form':website_form,
                 'form' : form,
                 'key' : key,
                 'appid' : appid,
                    }, context_instance=RequestContext(request))
示例#7
0
def signup_publisher_step4(request):
    ''' Fourth step of publisher signup process, confirms the email'''
    from forms import PublisherSignupForm3, WebsiteForm, PaymentInfoForm, ContactInfoForm, ContactInfoFormSmallest
    from atrinsic.util.user import generate_username
    from atrinsic.base.models import PublisherApplication, Organization, Website, OrganizationContacts, OrganizationPaymentInfo, User, UserProfile

    if request.method == "GET":
        if request.GET.get("id", None) and request.GET.get("key", None):
            if PublisherApplication.objects.filter(
                    validation_code=request.GET['key'],
                    id=request.GET['id']).count() > 0:
                app = PublisherApplication.objects.filter(
                    validation_code=request.GET['key'],
                    id=request.GET['id'])[0]
                form = PublisherSignupForm3(False)
                website_form = WebsiteForm()
                payment_form = PaymentInfoForm()
                print app.email
                inits = {
                    'payeename': '',
                    'firstname': '',
                    'lastname': '',
                    'phone': '',
                    'email': app.email,
                }
                formCI = ContactInfoForm(initial=inits)
                inits = {
                    'xs_firstname': '',
                    'xs_lastname': '',
                    'xs_email': app.email,
                }
                formCIxs = ContactInfoFormSmallest(initial=inits)
                key = request.GET['key']
                appid = request.GET['id']

                return AQ_render_to_response(
                    request,
                    'signup/publisher_newStep.html', {
                        'payment_form': payment_form,
                        'formCI': formCI,
                        'formCIxs': formCIxs,
                        'website_form': website_form,
                        'form': form,
                        'key': key,
                        'appid': appid,
                    },
                    context_instance=RequestContext(request))
            else:
                #application could not be found
                return AQ_render_to_response(
                    request,
                    'signup/appnotfound.html', {},
                    context_instance=RequestContext(request))
        else:
            return AQ_render_to_response(
                request,
                'signup/publisher_step4.html', {},
                context_instance=RequestContext(request))
    else:

        form = PublisherSignupForm3(False, request.POST)
        website_form = WebsiteForm(request.POST)
        payment_form = PaymentInfoForm(request.POST)
        formCI = ContactInfoForm(request.POST)
        formCIxs = ContactInfoFormSmallest(request.POST)
        key = request.POST['key']
        appid = request.POST['appid']

        if form.is_valid() and website_form.is_valid(
        ) and payment_form.is_valid():
            useSmallContactForm = True
            if payment_form.cleaned_data['payment_method'] == PAYMENT_CHECK:
                if formCI.is_valid():
                    useSmallContactForm = False
                else:
                    #1 or more forms are not valid
                    return AQ_render_to_response(
                        request,
                        'signup/publisher_newStep.html', {
                            'payment_form': payment_form,
                            'formCI': formCI,
                            'formCIxs': formCIxs,
                            'website_form': website_form,
                            'form': form,
                            'key': key,
                            'appid': appid,
                        },
                        context_instance=RequestContext(request))
            else:
                if formCIxs.is_valid():
                    useSmallContactForm = True
                else:
                    #1 or more forms are not valid
                    return AQ_render_to_response(
                        request,
                        'signup/publisher_newStep.html', {
                            'payment_form': payment_form,
                            'formCI': formCI,
                            'formCIxs': formCIxs,
                            'website_form': website_form,
                            'form': form,
                            'key': key,
                            'appid': appid,
                        },
                        context_instance=RequestContext(request))
            #create Organization

            org = Organization.objects.create(org_type=ORGTYPE_PUBLISHER,
                                              status=ORGSTATUS_UNAPPROVED)

            org.company_name = form.cleaned_data['company_name']
            org.address = form.cleaned_data['pub_address']
            org.address2 = form.cleaned_data['pub_address2']
            org.city = form.cleaned_data['pub_city']
            org.state = form.cleaned_data['pub_state']
            org.zipcode = form.cleaned_data['pub_zipcode']
            org.country = form.cleaned_data['pub_country']
            if str(website_form.cleaned_data['vertical']) == "Adult":
                org.is_adult = 1
            org.save()

            if useSmallContactForm:
                org_contact = OrganizationContacts.objects.create(
                    organization=org,
                    firstname=formCIxs.cleaned_data['xs_firstname'],
                    lastname=formCIxs.cleaned_data['xs_lastname'],
                    email=formCIxs.cleaned_data['xs_email'])
                org_contact.save()
            else:
                org_contact = OrganizationContacts.objects.create(
                    organization=org, **formCI.cleaned_data)
                org_contact.save()
                address = formCI.cleaned_data['address']
            app = PublisherApplication.objects.filter(validation_code=key,
                                                      id=appid)[0]

            try:
                term_log = Terms_Accepted_Log.objects.get(organization_id=app)
                term_log.organization_id = org.id
                term_log.save()
            except:
                pass

            address = ""
            website = Website.objects.create(publisher=org,
                                             is_default=True,
                                             **website_form.cleaned_data)
            website.save()
            org_payment = OrganizationPaymentInfo.objects.create(
                organization=org, **payment_form.cleaned_data)
            org_payment.save()

            first_name = app.first_name
            last_name = app.last_name
            password = app.password

            if useSmallContactForm:
                email = formCIxs.cleaned_data['xs_email']
            else:
                email = formCI.cleaned_data['email']

            if payment_form.cleaned_data['payment_method'] == PAYMENT_CHECK:
                payee_name = formCI.cleaned_data['payeename']
                first_name = formCI.cleaned_data['firstname']
                last_name = formCI.cleaned_data['lastname']

            # Create User, Set Password, Map to Organization
            u = User.objects.create(first_name=first_name,
                                    last_name=last_name,
                                    password=password,
                                    email=email,
                                    username=generate_username(email))
            up = UserProfile.objects.create(user=u)
            up.organizations.add(org)

            # Assign all ADMINLEVEL_ADMINISTRATOR to this
            for up in UserProfile.objects.filter(
                    admin_level=ADMINLEVEL_ADMINISTRATOR):
                up.admin_assigned_organizations.add(org)
                up.save()

            #Emails
            from django.core.mail import EmailMultiAlternatives
            print "Sending mail"
            msg = EmailMultiAlternatives(
                "Atrinsic Affiliate Network  Publisher Application", u"""
Dear """ + first_name[0:1].upper() + first_name[1:] + """ """ +
                last_name[0:1].upper() + last_name[1:] + """,

Thank you for applying to become a publisher on the Atrinsic Affiliate Network.

Your application has been placed in our queue and will be reviewed as quickly as possible.  You will be contacted shortly by a member of the Atrinsic Affiliate Network Publisher team to verify some information on your application.
If, at any time, you have questions or concerns, please contact us at [email protected].

We receive a large volume of applications each day and your application will be processed in the order in which it was received.


Thank you for your interest in working with Atrinsic Affiliate Network!

Sincerely,

The Atrinsic Affiliate Network Publisher Team

""", "*****@*****.**", [email])

            msg.send()

            themessage = u"""Dear Admin! this is a glorious day, a new publisher has join our ranks.
            Name: """ + first_name[0:1].upper() + first_name[
                1:] + """ """ + last_name[0:1].upper() + last_name[1:]
            themessage += """
            Address: """ + address + """
            Email: """ + email + """
            Website URL: """ + website_form.cleaned_data['url'] + """
            
            please review this application,
            
            Sincerely,
            
            The Atrinsic Affiliate Network Robot that sends email"""

            msg2 = EmailMultiAlternatives(
                "Atrinsic Affiliate Network Publisher Application", themessage,
                "*****@*****.**",
                ['*****@*****.**'])
            msg2.send()

            return AQ_render_to_response(
                request,
                'signup/publisher_complete.html', {},
                context_instance=RequestContext(request))

        else:
            #1 or more forms are not valid
            return AQ_render_to_response(
                request,
                'signup/publisher_newStep.html', {
                    'payment_form': payment_form,
                    'formCI': formCI,
                    'formCIxs': formCIxs,
                    'website_form': website_form,
                    'form': form,
                    'key': key,
                    'appid': appid,
                },
                context_instance=RequestContext(request))
示例#8
0
def network_publisher_create(request,oid=None):
    from atrinsic.base.models import Organization,Website,OrganizationContacts,OrganizationPaymentInfo,UserProfile,User
    from forms import PublisherSignupForm2,PublisherSignupForm3,PaymentInfoForm,ContactInfoForm,WebsiteForm

    if request.POST:
        update = False
        if oid:
            org = Organization.objects.get(pk=oid)
            update = True
            
        form_step2 = PublisherSignupForm2(update, request.POST)
        form_step3 = PublisherSignupForm3(update, request.POST)
        form_payment = PaymentInfoForm(request.POST)
        form_contact_info = ContactInfoForm(request.POST)
        website_form = WebsiteForm(request.POST)
        
        if form_step2.is_valid() & form_step3.is_valid() & form_payment.is_valid() & form_contact_info.is_valid() & website_form.is_valid():
            if oid:
                org = Organization.objects.get(pk=oid)
            else:
                org = Organization.objects.create(org_type=ORGTYPE_PUBLISHER, status=ORGSTATUS_UNAPPROVED)
           
            org.company_name = form_step3.cleaned_data['company_name']
            org.address = form_step3.cleaned_data['pub_address']
            org.address2 = form_step3.cleaned_data['pub_address2']
            org.city = form_step3.cleaned_data['pub_city']
            org.state = form_step3.cleaned_data['pub_state']
            org.zipcode = form_step3.cleaned_data['pub_zipcode']
            org.country = form_step3.cleaned_data['pub_country']
            org.save()     
                
                
            if update:
                website = Website.objects.filter(publisher=org,is_default=True).update(**website_form.cleaned_data)
                org_contact = OrganizationContacts.objects.filter(organization=org).update(**form_contact_info.cleaned_data)
                org_payment = OrganizationPaymentInfo.objects.filter(organization=org).update(**form_payment.cleaned_data)
                '''
                user_form_cleaned = form_step2.cleaned_data
                del user_form_cleaned['password2']
                up = UserProfile.objects.get(organizations=org)
                up.user.first_name=user_form_cleaned['first_name']
                up.user.last_name=user_form_cleaned['last_name']
                up.user.email=user_form_cleaned['email']
                up.user.username=user_form_cleaned['username']
                if user_form_cleaned['password']:
                    up.user.set_password(user_form_cleaned['password'])
                up.user.save()
                up.save()
                '''
            else:
                website = Website.objects.create(publisher = org, is_default = True, **website_form.cleaned_data)
                org_contact = OrganizationContacts.objects.create(organization=org, email=form_step2.cleaned_data['email'], **form_contact_info.cleaned_data)
                org_payment = OrganizationPaymentInfo.objects.create(organization=org, **form_payment.cleaned_data)
                org_contact.save()
                org_payment.save()
                website.save()
                
                user_form_cleaned = form_step2.cleaned_data
                del user_form_cleaned['password2']
                u = User.objects.create(**user_form_cleaned)
                up = UserProfile.objects.create(user=u)
                up.organizations.add(org)

            
            for up in UserProfile.objects.filter(admin_level=ADMINLEVEL_ADMINISTRATOR):
                up.admin_assigned_organizations.add(org)
                up.save()
            return HttpResponseRedirect("/network/publisher/settings/")
    else:
        if oid:
            org = Organization.objects.get(pk=oid)
            org_contact = OrganizationContacts.objects.get(organization=org)
            org_payment_info = OrganizationPaymentInfo.objects.get(organization=org)
            website = Website.objects.get(publisher=org, is_default = True)
            up = UserProfile.objects.filter(organizations=org).select_related("user")[0]
            
            form_step2 = PublisherSignupForm2(True, initial={'first_name':up.user.first_name, 'last_name':up.user.last_name, 'email':up.user.email, })
            form_step3 = PublisherSignupForm3(True, initial={'company_name':org.company_name,'pub_address':org.address,'pub_address2':org.address2, 'pub_city':org.city,
                                                'pub_state':org.state,'pub_zipcode':org.zipcode, 'pub_country':org.country, 'pub_province':org.state})
            form_payment = PaymentInfoForm(instance=org_payment_info)
            form_contact_info = ContactInfoForm(instance=org_contact)
            website_form = WebsiteForm(instance=website)
        else:
            form_step2 = PublisherSignupForm2()
            form_step3 = PublisherSignupForm3()
            form_payment = PaymentInfoForm()
            form_contact_info = ContactInfoForm()
            website_form = WebsiteForm(organization=request.organization)
        
    return AQ_render_to_response(request, 'network/publisher/create.html', {
            'form_step2':form_step2,
            'form_step3':form_step3,
            'form_payment':form_payment,
            'website_form':website_form,
            'form_contact_info':form_contact_info,
        }, context_instance=RequestContext(request))