Commits

alexey.sveshnikov  committed b7de069 Merge

merged with main repo

  • Participants
  • Parent commits 6c5d874, 488ecf6

Comments (0)

Files changed (12)

File lfs/cart/tests.py

 class CartModelsTestCase(TestCase):
     """
     """
+    fixtures = ['lfs_shop.xml']
     def setUp(self):
         """
         """
 class AddToCartTestCase(TestCase):
     """Test case for add_to_cart view.
     """
+    fixtures = ['lfs_shop.xml']
     def setUp(self):
         """
         """

File lfs/checkout/forms.py

 import lfs.payment.settings
 from lfs.payment.models import PaymentMethod
 from lfs.core.utils import get_default_shop
+from lfs.core.models import Country
 
 class OnePageCheckoutForm(forms.Form):
     """
             if self.cleaned_data.get("shipping_lastname", "") == "":
                 self._errors["shipping_lastname"] = ErrorList([msg])
 
+        # check that shipping country is in the shops shipping countries list
+        shop = get_default_shop()
+        shipping_countries = shop.shipping_countries.all()
+        shipping_country = None
+        if not self.cleaned_data.get("no_shipping"):
+            shipping_country_code = self.data.get("shipping-country", None)
+            if shipping_country_code:
+                shipping_country = Country.objects.get(code=shipping_country_code.lower())
+        else:
+            shipping_country_code = self.data.get("invoice-country", None)
+            if shipping_country_code:
+                shipping_country = Country.objects.get(code=shipping_country_code.lower())
+        if shipping_country:
+            if shipping_country not in shipping_countries:
+                msg = _(u"Invalid shipping country.")
+                #self._errors["all"] = ErrorList([msg])
+                raise forms.ValidationError("Invalid Shipping Country")
+
 		# Check data of selected payment method        
         payment_method_id = self.data.get("payment_method")        
         payment_method = PaymentMethod.objects.get(pk=payment_method_id)

File lfs/checkout/tests/test_addresses.py

         # get our new customer
         our_customer = Customer.objects.get(user__email="test@test.com")
         self.assertNotEqual(our_customer, None)
-        self.assertEqual(our_customer.selected_invoice_address, None)
-        self.assertEqual(our_customer.selected_shipping_address, None)
+        self.assertNotEqual(our_customer.selected_invoice_address, None)
+        self.assertNotEqual(our_customer.selected_shipping_address, None)
 
         # test that an ajax request creates a new customer address
         form_data = {'invoice-country': 'ie'}
         ajax_respons = self.c.post(reverse('lfs_changed_invoice_country'), form_data)
-        self.assertEquals(Address.objects.count(), 3)
+        self.assertEquals(Address.objects.count(), 4)
 
         # refetch our customer
         our_customer = Customer.objects.get(user__email="test@test.com")
         self.assertNotEqual(our_customer.selected_invoice_address, None)
-        self.assertEqual(our_customer.selected_shipping_address, None)
+        self.assertNotEqual(our_customer.selected_shipping_address, None)
 
         # test that we still have the same number of Addresses after another invoice post
         form_data = {'invoice-line1': 'my house',
                      'invoice-state': 'a state',
                      }
         ajax_respons = self.c.post(reverse('lfs_changed_invoice_country'), form_data)
-        self.assertEquals(Address.objects.count(), 3)
+        self.assertEquals(Address.objects.count(), 4)
 
         # post some shipping address info
         form_data = {'shipping-line1': 'de missusesss house'}

File lfs/checkout/tests/test_checkout.py

         self.assertContains(cart_response, self.PRODUCT1_NAME, status_code=200)
 
         checkout_response = self.c.get(reverse('lfs_checkout'))
-        self.assertContains(checkout_response, '<option value="de" selected="selected">Deutschland</option>', status_code=200)
+        self.assertContains(checkout_response, '<option value="DE" selected="selected">Deutschland</option>', status_code=200)
 
     def test_order_phone_email_set_after_checkout(self):
         # login as our customer

File lfs/checkout/views.py

 
         if toc and form.is_valid():
             # save invoice details
-            if customer.selected_invoice_address is None:
-                customer.selected_invoice_address = Address.objects.create(customer=customer, country=shop.default_country)
-                customer.save()
             customer.selected_invoice_address.firstname = request.POST.get("invoice_firstname")
             customer.selected_invoice_address.lastname = request.POST.get("invoice_lastname")
             customer.selected_invoice_address.phone = request.POST.get("invoice_phone")
                 valid_shipping_address = True
                 if not form.cleaned_data.get("no_shipping"):
                     # save shipping details
-                    if customer.selected_shipping_address is None:
-                        customer.selected_shipping_address = Address.objects.create(customer=customer, country=shop.default_country)
-                        customer.save()
                     customer.selected_shipping_address.firstname = request.POST.get("shipping_firstname")
                     customer.selected_shipping_address.lastname = request.POST.get("shipping_lastname")
                     customer.selected_shipping_address.phone = request.POST.get("shipping_phone")
     else:
         # If there are addresses intialize the form.
         initial = {}
-        if customer.selected_invoice_address is None:
-            customer.selected_invoice_address = Address.objects.create(customer=customer, country=shop.default_country)
-            customer.save()
         invoice_address = customer.selected_invoice_address
         initial.update({
             "invoice_firstname" : invoice_address.firstname,
             "invoice_email" : invoice_address.email,
             "invoice_country" : invoice_address.country,
         })
-        if customer.selected_shipping_address is None:
-            customer.selected_shipping_address = Address.objects.create(customer=customer, country=shop.default_country)
-            customer.save()
         shipping_address = customer.selected_shipping_address
         initial.update({
             "shipping_firstname" : shipping_address.firstname,
         country_iso = request.POST.get("invoice-country", None)
 
     if country_iso is not None:
-        country = Country.objects.get(code=country_iso)
+        country = Country.objects.get(code=country_iso.lower())
         if customer.selected_shipping_address:
             customer.selected_shipping_address.country = country
             customer.selected_shipping_address.save()

File lfs/core/models.py

-# python imports
-import re
-
 # django imports
 from django.core.cache import cache
 from django.db import models
     def get_notification_emails(self):
         """Returns the notification e-mail addresses as list
         """
+        import re
         adresses = re.split("[\s,]+", self.notification_emails)
         return adresses
 

File lfs/customer/tests.py

 
         our_user = User.objects.get(email='test@test.com')
         our_customer = Customer.objects.get(user=our_user)
-        self.assertEquals(our_customer.selected_invoice_address, None)
-        self.assertEquals(our_customer.selected_shipping_address, None)
+        self.assertNotEquals(our_customer.selected_invoice_address, None)
+        self.assertNotEquals(our_customer.selected_shipping_address, None)
 
         # see if we can view the addresss page
         address_data = {'invoice_firstname': 'Joe', 'invoice_lastname': 'Bloggs',

File lfs/customer/utils.py

 from django.core.exceptions import ObjectDoesNotExist
 
 # lfs imports
-from lfs.customer.models import Customer
+from lfs.customer.models import Customer, Address
+from lfs.core.utils import get_default_shop
 
 def get_or_create_customer(request):
     """Get or creates the customer object.
     customer = Customer(session = request.session.session_key)
     if request.user.is_authenticated():
         customer.user = request.user
-
+    shop = get_default_shop()
+    customer.selected_invoice_address = Address.objects.create(customer=customer, country=shop.default_country)
+    customer.selected_shipping_address = Address.objects.create(customer=customer, country=shop.default_country)
     customer.save()
     return customer
 

File lfs/customer/views.py

             else:
                 address_form = PostalAddressForm(prefix=prefix, data=request.POST,)
             if countries is not None:
-                address_form.fields["country"].choices = [(c.code, c.name) for c in countries]
+                address_form.fields["country"].choices = [(c.code.upper(), c.name) for c in countries]
             save_address(request, customer, prefix)
         else:
             # If there are addresses intialize the form.
                     "city" : customer_selected_address.city,
                     "state" : customer_selected_address.state,
                     "code" : customer_selected_address.zip_code,
-                    "country" : customer_selected_address.country.code,
+                    "country" : customer_selected_address.country.code.upper(),
                 })
                 address_form = address_form_class(prefix=prefix, initial=initial)
             else:
                 address_form = address_form_class(prefix=prefix)
                 address_form.fields["country"].initial = country_code
             if countries is not None:
-                address_form.fields["country"].choices = [(c.code, c.name) for c in countries]
+                address_form.fields["country"].choices = [(c.code.upper(), c.name) for c in countries]
 
     # Removes fields from address form if requested via settings.
     for i in range(1, 6):
             customer_selected_address.city = request.POST.get(prefix + "-city", "")
             customer_selected_address.state = request.POST.get(prefix + "-state", "")
             customer_selected_address.zip_code = request.POST.get(prefix + "-code", "")
-            customer_selected_address.country = Country.objects.get(code=country_iso)
+            customer_selected_address.country = Country.objects.get(code=country_iso.lower())
             customer_selected_address.save()
     if not existing_address:
         # no address exists for customer so create one
                                                             city=request.POST.get(prefix + "-city", ""),
                                                             state=request.POST.get(prefix + "-state", ""),
                                                             zip_code=request.POST.get(prefix + "-code", ""),
-                                                            country=Country.objects.get(code=country_iso))
+                                                            country=Country.objects.get(code=country_iso.lower()))
     setattr(customer, address_attribute, customer_selected_address)
     customer.save()
     return customer_selected_address

File lfs/payment/utils.py

 
     elif payment_method.id == PAYPAL:
         order = lfs.order.utils.add_order(request)
-        order_submitted.send({"order" : order, "request" : request})
-        if settings.LFS_PAYPAL_REDIRECT:
-            return {
-                "accepted" : True,
-                "next-url" : order.get_pay_link(),
-            }
-        else:
-            return {
-                "accepted" : True,
-                "next-url" : reverse("lfs_thank_you"),
-            }
+        if order: # if we have no cart then the order will be None
+            order_submitted.send({"order" : order, "request" : request})
+            if settings.LFS_PAYPAL_REDIRECT:
+                return {
+                    "accepted" : True,
+                    "next-url" : order.get_pay_link(),
+                }
+        return {
+            "accepted" : True,
+            "next-url" : reverse("lfs_thank_you"),
+        }
     else:
         order = lfs.order.utils.add_order(request)
         order_submitted.send({"order" : order, "request" : request})

File lfs/shipping/tests.py

 class ShippingMethodTestCase(TestCase):
     """Unit tests for lfs.shipping
     """
-    fixtures = ["lfs_user.xml"]
+    fixtures = ['lfs_shop.xml', "lfs_user.xml"]
     
     def setUp(self):
         """

File lfs/static/js/lfs.js

     // Product ################################################################
 
     $("a.product-image").lightBox({
-        "txtImage" : "Bild",
-        "txtOf" : " von "
+        "txtImage" : "Image",
+        "txtOf" : " of "
     });
 
     // Hack to make the change event on radio buttons for IE working
 
                 // Re-bind lightbox
                 $("a.product-image").lightBox({
-                    "txtImage" : "Bild",
-                    "txtOf" : " von "
+                    "txtImage" : "Image",
+                    "txtOf" : " of "
                 });
             }
         });
 
                 // Re-bind lightbox
                 $("a.product-image").lightBox({
-                    "txtImage" : "Bild",
-                    "txtOf" : " von "
+                    "txtImage" : "Image",
+                    "txtOf" : " of "
                 });
             }
         });
 
                 // Re-bind lightbox
                 $("a.product-image").lightBox({
-                    "txtImage" : "Bild",
-                    "txtOf" : " von "
+                    "txtImage" : "Image",
+                    "txtOf" : " of "
                 });
             }
         });