Commits

mickt committed 97d6a3c

validate shipping and invoice addresses

  • Participants
  • Parent commits e2c592e

Comments (0)

Files changed (4)

File lfs/checkout/tests/test_addresses.py

                          'invoice-city': 'de area',
                          'invoice-state': 'de town',
                          'invoice-code': 'cork',
-                         'invoice-country': "ie",
+                         'invoice-country': "IE",
                          'invoice_email': 'a@a.com',
                          'invoice_phone': '1234567',
                          'shipping_firstname': 'hans',
                          'shipping-city': 'stuff',
                          'shipping-state': 'BE',
                          'shipping-code': '12345',
-                         'shipping-country': "de",
+                         'shipping-country': "DE",
                          'shipping_email': 'b@b.com',
                          'shipping_phone': '7654321',
                          'payment_method': self.by_invoice.id,

File lfs/checkout/tests/test_checkout.py

                          'invoice-city': 'de area',
                          'invoice-state': 'de town',
                          'invoice-code': 'cork',
-                         'invoice-country': "ie",
+                         'invoice-country': "IE",
                          'invoice_email': 'a@a.com',
                          'invoice_phone': '1234567',
                          'shipping_firstname': 'hans',
                          'shipping-city': 'stuff',
                          'shipping-state': 'BE',
                          'shipping-code': '12345',
-                         'shipping-country': "de",
+                         'shipping-country': "DE",
                          'payment_method': self.by_invoice.id,
                          'shipping_email': 'b@b.com',
                          'shipping_phone': '7654321',
         self.assertEqual(logged_in, True)
 
         # test that our Netherlands form has only 4 address line fields
-        nl_form_class = form_factory("nl")
+        nl_form_class = form_factory("NL")
         nl_form = nl_form_class()
         self.assertEqual('state' in nl_form.fields, False)
         self.assertEqual('code' in nl_form.fields, True)
                          'invoice-line2': 'de street',
                          'invoice-city': 'de area',
                          'invoice-state': 'de town',
-                         'invoice-code': 'cork',
-                         'invoice-country': "nl",
+                         'invoice-code': '1234AB',
+                         'invoice-country': "NL",
                          'invoice_email': 'a@a.com',
                          'invoice_phone': '1234567',
                          'shipping_firstname': 'hans',
                          'shipping-line2': 'de town',
                          'shipping-city': 'stuff',
                          'shipping-state': 'BE',
-                         'shipping-code': '12345',
-                         'shipping-country': "nl",
+                         'shipping-code': '1234AB',
+                         'shipping-country': "NL",
                          'payment_method': self.by_invoice.id,
                          'shipping_email': 'b@b.com',
                          'shipping_phone': '7654321',

File lfs/checkout/views.py

 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.forms.util import ErrorList
+from django.forms.forms import NON_FIELD_ERRORS
 from django.http import HttpResponse
 from django.http import HttpResponseRedirect
 from django.shortcuts import render_to_response
             # Create or update invoice address
             valid_invoice_address = save_address(request, customer, INVOICE_PREFIX)
             if valid_invoice_address == False:
-                form._errors["invoice-address"] = ErrorList([_(u"Invalid invoice address")])
+                form._errors.setdefault(NON_FIELD_ERRORS, ErrorList([_(u"Invalid invoice address")]))
             else:
                 # If the shipping address differs from invoice firstname we create
                 # or update the shipping address.
                     valid_shipping_address = save_address(request, customer, SHIPPING_PREFIX)
 
                 if valid_shipping_address == False:
-                    form._errors["shipping-address"] = ErrorList([_(u"Invalid shipping address")])
+                    form._errors.setdefault(NON_FIELD_ERRORS, ErrorList([_(u"Invalid shipping address")]))
                 else:
                     # Payment method
                     customer.selected_payment_method_id = request.POST.get("payment_method")

File lfs/customer/views.py

 
     # get the country for the address
     country_iso = request.POST.get(prefix + "-country", shop.default_country.code)
+
+    # check have we a valid address
+    form_class = form_factory(country_iso)
+    valid_address = False
+    form_obj = form_class(request.POST, prefix=prefix)
+    if form_obj.is_valid():
+        valid_address = True
+
     customer_selected_address = None
     address_attribute = 'selected_' + prefix + '_address'
     existing_address = False
                                                            country=Country.objects.get(code=country_iso.lower()))
     setattr(customer, address_attribute, customer_selected_address)
     customer.save()
-    return customer_selected_address
+    return valid_address
 
 
 @login_required