コード例 #1
0
ファイル: views.py プロジェクト: abrar78/satchmo
def update(request):
    """Update contact info"""

    init_data = {}
    areas, countries, only_country = get_area_country_options(request)

    contact = Contact.from_request(request, create=False)

    if request.POST:
        new_data = request.POST.copy()
        form = ExtendedContactInfoForm(countries, areas, new_data,
            initial=init_data)

        if form.is_valid():
            if contact is None and request.user:
                contact = Contact(user=request.user)
            custID = form.save(contact=contact)
            request.session['custID'] = custID
            url = urlresolvers.reverse('satchmo_account_info')
            return http.HttpResponseRedirect(url)
        else:
            if config_get_group('NEWSLETTER'):
                show_newsletter = True
            else:
                show_newsletter = False

    else:
        if contact:
            #If a person has their contact info, make sure we populate it in the form
            for item in contact.__dict__.keys():
                init_data[item] = getattr(contact,item)
            if contact.shipping_address:
                for item in contact.shipping_address.__dict__.keys():
                    init_data["ship_"+item] = getattr(contact.shipping_address,item)
            if contact.billing_address:
                for item in contact.billing_address.__dict__.keys():
                    init_data[item] = getattr(contact.billing_address,item)
            if contact.primary_phone:
                init_data['phone'] = contact.primary_phone.phone
            
        show_newsletter = False
        current_subscriber = False
        if config_get_group('NEWSLETTER'):
            show_newsletter = True
            if contact:
                from satchmo.newsletter import is_subscribed
                current_subscriber = is_subscribed(contact)

        init_data['newsletter'] = current_subscriber
            
        form = ExtendedContactInfoForm(countries, areas, initial=init_data)

    context = RequestContext(request, {
        'form': form,
        'country': only_country,
        'show_newsletter': show_newsletter})
    return render_to_response('contact/update_form.html', context)
コード例 #2
0
ファイル: common_contact.py プロジェクト: abrar78/satchmo
def contact_info(request):
    """View which collects demographic information from customer."""

    #First verify that the cart exists and has items
    if request.session.get('cart'):
        tempCart = Cart.objects.get(id=request.session['cart'])
        if tempCart.numItems == 0:
            return render_to_response('checkout/empty_cart.html', RequestContext(request))
    else:
        return render_to_response('checkout/empty_cart.html', RequestContext(request))

    init_data = {}
    areas, countries, only_country = get_area_country_options(request)

    contact = Contact.from_request(request, create=False)

    if request.POST:
        new_data = request.POST.copy()
        if not tempCart.is_shippable:
            new_data['copy_address'] = True
        form = PaymentContactInfoForm(countries, areas, new_data,
            initial=init_data)

        if form.is_valid():
            if contact is None and request.user:
                contact = Contact(user=request.user)
            custID = form.save(contact=contact, update_newsletter=False)
            request.session['custID'] = custID
            #TODO - Create an order here and associate it with a session
            modulename = 'PAYMENT_' + new_data['paymentmethod']
            paymentmodule = config_get_group(modulename)
            url = lookup_url(paymentmodule, 'satchmo_checkout-step2')
            return http.HttpResponseRedirect(url)
    else:
        if contact:
            #If a person has their contact info, make sure we populate it in the form
            for item in contact.__dict__.keys():
                init_data[item] = getattr(contact,item)
            if contact.shipping_address:
                for item in contact.shipping_address.__dict__.keys():
                    init_data["ship_"+item] = getattr(contact.shipping_address,item)
            if contact.billing_address:
                for item in contact.billing_address.__dict__.keys():
                    init_data[item] = getattr(contact.billing_address,item)
            if contact.primary_phone:
                init_data['phone'] = contact.primary_phone.phone
        else:
            # Allow them to login from this page.
            request.session.set_test_cookie()
        form = PaymentContactInfoForm(countries, areas, initial=init_data)

    context = RequestContext(request, {
        'form': form,
        'country': only_country,
        'paymentmethod_ct': len(config_value('PAYMENT', 'MODULES'))
        })
    return render_to_response('checkout/form.html', context)
コード例 #3
0
ファイル: common_contact.py プロジェクト: yusufbs/satchmo
def contact_info(request):
    """View which collects demographic information from customer."""

    # First verify that the cart exists and has items
    if request.session.get("cart"):
        tempCart = Cart.objects.get(id=request.session["cart"])
        if tempCart.numItems == 0:
            return render_to_response("checkout/empty_cart.html", RequestContext(request))
    else:
        return render_to_response("checkout/empty_cart.html", RequestContext(request))

    init_data = {}
    areas, countries, only_country = get_area_country_options(request)

    contact = Contact.from_request(request, create=False)

    if request.POST:
        new_data = request.POST.copy()
        if not tempCart.is_shippable:
            new_data["copy_address"] = True
        form = PaymentContactInfoForm(countries, areas, new_data, initial=init_data)

        if form.is_valid():
            if contact is None and request.user:
                contact = Contact(user=request.user)
            custID = form.save(contact=contact, update_newsletter=False)
            request.session["custID"] = custID
            # TODO - Create an order here and associate it with a session
            modulename = "PAYMENT_" + new_data["paymentmethod"]
            paymentmodule = config_get_group(modulename)
            url = lookup_url(paymentmodule, "satchmo_checkout-step2")
            return http.HttpResponseRedirect(url)
    else:
        if contact:
            # If a person has their contact info, make sure we populate it in the form
            for item in contact.__dict__.keys():
                init_data[item] = getattr(contact, item)
            if contact.shipping_address:
                for item in contact.shipping_address.__dict__.keys():
                    init_data["ship_" + item] = getattr(contact.shipping_address, item)
            if contact.billing_address:
                for item in contact.billing_address.__dict__.keys():
                    init_data[item] = getattr(contact.billing_address, item)
            if contact.primary_phone:
                init_data["phone"] = contact.primary_phone.phone
        else:
            # Allow them to login from this page.
            request.session.set_test_cookie()
        form = PaymentContactInfoForm(countries, areas, initial=init_data)

    context = RequestContext(
        request, {"form": form, "country": only_country, "paymentmethod_ct": len(config_value("PAYMENT", "MODULES"))}
    )
    return render_to_response("checkout/form.html", context)