Commits

Radim Novotny  committed 0f62326

Fixed problem with locale.atof which caused not working conversion to number in some environments. atof needs encoded string, not unicode

  • Participants
  • Parent commits 8243387

Comments (0)

Files changed (1)

File lfs/cart/views.py

         raise Http404()
 
     try:
-        quantity = locale.atof(request.POST.get("quantity", "1.0"))
+        value = request.POST.get("quantity", "1.0")
+        if isinstance(value, unicode):
+            # atof() on unicode string fails in some environments, like Czech
+            value = value.encode("utf-8")
+        quantity = locale.atof(value)
     except (TypeError, ValueError):
         quantity = 1.0
 
 
                 if property.is_number_field:
                     try:
+                        if isinstance(value, unicode):
+                            # atof() on unicode string fails in some environments, like Czech
+                            value = value.encode("utf-8")
                         value = locale.atof(value)
                     except ValueError:
                         value = locale.atof("0.0")
     message = ""
     for item in cart.get_items():
         try:
-            amount = locale.atof(request.POST.get("amount-cart-item_%s" % item.id, "0.0"))
+            value = request.POST.get("amount-cart-item_%s" % item.id, "0.0")
+            if isinstance(value, unicode):
+                # atof() on unicode string fails in some environments, like Czech
+                value = value.encode("utf-8")
+            amount = locale.atof(value)
         except (TypeError, ValueError):
             amount = 1.0