def update(request):
    """Update contact info"""

    init_data = {}
    shop = Config.objects.get_current()

    try:
        contact = Contact.objects.from_request(request, create=False)
    except Contact.DoesNotExist:
        contact = None


    if request.method == "POST":
        new_data = request.POST.copy()
        form = ExtendedContactInfoForm(data=new_data, shop=shop, contact=contact, shippable=True,
            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[CUSTOMER_ID] = custID
            redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = urlresolvers.reverse('satchmo_account_info')

            return http.HttpResponseRedirect(redirect_to)
        else:
            signals.satchmo_contact_view.send(contact, contact=contact, contact_dict=init_data)

    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
            if contact.organization:
                init_data['organization'] = contact.organization.name


        signals.satchmo_contact_view.send(contact, contact=contact, contact_dict=init_data)
        form = ExtendedContactInfoForm(shop=shop, contact=contact, shippable=True, initial=init_data)

    init_data['form'] = form
    if shop.in_country_only:
        init_data['country'] = shop.sales_country
    else:
        countries = shop.countries()
        if countries and countries.count() == 1:
            init_data['country'] = countries[0]


    init_data['next'] = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
    context = RequestContext(request, init_data)

    return render_to_response('contact/update_form.html',
                              context_instance=context)
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_store/contact/views.py/update/original