Esempio n. 1
0
def addresses(request, template_name="lfs/customer/addresses.html"):
    """Provides a form to edit addresses and bank account.
    """
    customer = lfs.customer.utils.get_customer(request)
    shop = lfs.core.utils.get_default_shop(request)

    if request.method == "POST":
        form = AddressForm(request.POST)
        if form.is_valid():
            save_address(request, customer, INVOICE_PREFIX)
            save_address(request, customer, SHIPPING_PREFIX)
            customer.selected_invoice_address.customer = customer
            customer.selected_invoice_address.firstname = form.cleaned_data['invoice_firstname']
            customer.selected_invoice_address.lastname = form.cleaned_data['invoice_lastname']
            customer.selected_invoice_address.phone = form.cleaned_data['invoice_phone']
            customer.selected_invoice_address.email = form.cleaned_data['invoice_email']
            customer.selected_invoice_address.save()
            customer.selected_shipping_address.customer = customer
            customer.selected_shipping_address.firstname = form.cleaned_data['shipping_firstname']
            customer.selected_shipping_address.lastname = form.cleaned_data['shipping_lastname']
            customer.selected_shipping_address.phone = form.cleaned_data['shipping_phone']
            customer.selected_shipping_address.email = form.cleaned_data['shipping_email']
            customer.selected_shipping_address.save()
            return HttpResponseRedirect(reverse("lfs_my_addresses"))
    else:
        initial = {}
        if customer:
            if customer.selected_invoice_address is not None:
                initial.update({"invoice_firstname": customer.selected_invoice_address.firstname,
                                "invoice_lastname": customer.selected_invoice_address.lastname,
                                "invoice_phone": customer.selected_invoice_address.phone,
                                "invoice_email": customer.selected_invoice_address.email,
                                })
            if customer.selected_shipping_address is not None:
                initial.update({"shipping_firstname": customer.selected_shipping_address.firstname,
                                "shipping_lastname": customer.selected_shipping_address.lastname,
                                "shipping_phone": customer.selected_shipping_address.phone,
                                "shipping_email": customer.selected_shipping_address.email,
                                })

        form = AddressForm(initial=initial)
    return render_to_response(template_name, RequestContext(request, {
        "form": form,
        "shipping_address_inline": address_inline(request, "shipping", form),
        "invoice_address_inline": address_inline(request, "invoice", form),
    }))
Esempio n. 2
0
def addresses(request, template_name="lfs/customer/addresses.html"):
    """Provides a form to edit addresses and bank account.
    """
    customer = lfs.customer.utils.get_customer(request)
    shop = lfs.core.utils.get_default_shop(request)

    if request.method == "POST":
        form = AddressForm(request.POST)
        if form.is_valid():
            save_address(request, customer, INVOICE_PREFIX)
            save_address(request, customer, SHIPPING_PREFIX)
            customer.selected_invoice_address.customer = customer
            customer.selected_invoice_address.firstname = form.cleaned_data['invoice_firstname']
            customer.selected_invoice_address.lastname = form.cleaned_data['invoice_lastname']
            customer.selected_invoice_address.phone = form.cleaned_data['invoice_phone']
            customer.selected_invoice_address.email = form.cleaned_data['invoice_email']
            customer.selected_invoice_address.save()
            customer.selected_shipping_address.customer = customer
            customer.selected_shipping_address.firstname = form.cleaned_data['shipping_firstname']
            customer.selected_shipping_address.lastname = form.cleaned_data['shipping_lastname']
            customer.selected_shipping_address.phone = form.cleaned_data['shipping_phone']
            customer.selected_shipping_address.email = form.cleaned_data['shipping_email']
            customer.selected_shipping_address.save()
            return HttpResponseRedirect(reverse("lfs_my_addresses"))
    else:
        initial = {}
        if customer:
            if customer.selected_invoice_address is not None:
                initial.update({"invoice_firstname": customer.selected_invoice_address.firstname,
                                "invoice_lastname": customer.selected_invoice_address.lastname,
                                "invoice_phone": customer.selected_invoice_address.phone,
                                "invoice_email": customer.selected_invoice_address.email,
                                })
            if customer.selected_shipping_address is not None:
                initial.update({"shipping_firstname": customer.selected_shipping_address.firstname,
                                "shipping_lastname": customer.selected_shipping_address.lastname,
                                "shipping_phone": customer.selected_shipping_address.phone,
                                "shipping_email": customer.selected_shipping_address.email,
                                })

        form = AddressForm(initial=initial)
    return render_to_response(template_name, RequestContext(request, {
        "form": form,
        "shipping_address_inline": address_inline(request, "shipping", form),
        "invoice_address_inline": address_inline(request, "invoice", form),
    }))
Esempio n. 3
0
File: views.py Progetto: potar/lfs
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,
            }))
Esempio n. 4
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,
    }))