Beispiel #1
0
def addresses(request, template_name="lfs/customer/addresses.html"):
    """Provides a form to edit addresses and bank account.
    """
    user = request.user
    customer = lfs.customer.utils.get_customer(request)

    show_shipping_address = customer.selected_shipping_address and \
                            customer.selected_invoice_address.id != \
                            customer.selected_shipping_address.id

    if request.method == "POST":
        shipping_form = AddressForm(
            prefix="shipping",
            data=request.POST,
            instance=customer.selected_shipping_address)

        invoice_form = AddressForm(prefix="invoice",
                                   data=request.POST,
                                   instance=customer.selected_invoice_address)

        if show_shipping_address:
            if shipping_form.is_valid() and invoice_form.is_valid():
                shipping_form.save()
                invoice_form.save()
                return HttpResponseRedirect(reverse("lfs_my_addresses"))
        else:
            if invoice_form.is_valid():
                invoice_form.save()
                return HttpResponseRedirect(reverse("lfs_my_addresses"))
    else:

        shipping_form = AddressForm(
            prefix="shipping", instance=customer.selected_shipping_address)

        invoice_form = AddressForm(prefix="invoice",
                                   instance=customer.selected_invoice_address)

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                "show_shipping_address": show_shipping_address,
                "shipping_address_form": shipping_form,
                "invoice_address_form": invoice_form,
            }))
Beispiel #2
0
def addresses(request, template_name="lfs/customer/addresses.html"):
    """Provides a form to edit addresses and bank account.
    """
    user = request.user
    customer = lfs.customer.utils.get_customer(request)
    
    show_shipping_address = customer.selected_shipping_address and \
                            customer.selected_invoice_address.id != \
                            customer.selected_shipping_address.id
    
    if request.method == "POST":    
        shipping_form = AddressForm(prefix="shipping", data=request.POST,
            instance = customer.selected_shipping_address)
        
        invoice_form = AddressForm(prefix="invoice", data=request.POST,
            instance = customer.selected_invoice_address)
    
        if show_shipping_address:
            if shipping_form.is_valid() and invoice_form.is_valid():
                shipping_form.save()
                invoice_form.save()
                return HttpResponseRedirect(reverse("lfs_my_addresses"))
        else:
            if invoice_form.is_valid():
                invoice_form.save()
                return HttpResponseRedirect(reverse("lfs_my_addresses"))
    else:            
        
        shipping_form = AddressForm(prefix="shipping",
            instance=customer.selected_shipping_address)
        
        invoice_form = AddressForm(prefix="invoice", 
            instance=customer.selected_invoice_address)
        
    return render_to_response(template_name, RequestContext(request, {
        "show_shipping_address" : show_shipping_address,
        "shipping_address_form" : shipping_form,
        "invoice_address_form" : invoice_form,
    }))