Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Implement style suggestions

Artur Smętf26698bce1a0
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
index d8fa6f3fdd..138eb9794f 100755
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -1,8 +1,8 @@
from __future__ import unicode_literals
+from django.conf import settings
from django.utils.translation import pgettext
from django.utils.encoding import python_2_unicode_compatible, smart_text
-from django.conf import settings
from satchless import cart
from satchless.item import ItemList
from saleor.product.models import Product
@@ -39,10 +39,11 @@ class Cart(cart.Cart):
for item in session_cart:
try:
product = product_map[item.data['product_id']]
- variant = product.variants.get(pk=item.data['variant_id'])
except KeyError:
# TODO: Provide error message
continue
+ else:
+ variant = product.variants.get(pk=item.data['variant_id'])
quantity = item.quantity
cart.add(variant, quantity=quantity, check_quantity=False)
return cart
@@ -77,16 +78,15 @@ class Cart(cart.Cart):
class SessionCartLine(cart.CartLine):
def get_price_per_item(self, **kwargs):
- gross = self.data.get('unit_price_gross')
- net = self.data.get('unit_price_net')
+ gross = self.data['unit_price_gross']
+ net = self.data['unit_price_net']
return Price(net=net, gross=gross, currency=settings.DEFAULT_CURRENCY)
def for_storage(self):
return {
'product': self.product,
'quantity': self.quantity,
- 'data': self.data
- }
+ 'data': self.data}
@classmethod
def from_storage(cls, data_dict):
@@ -113,9 +113,8 @@ class SessionCart(cart.Cart):
def for_storage(self):
cart_data = {
'items': [i.for_storage() for i in self],
- 'modified': False
- }
+ 'modified': False}
return cart_data
def create_line(self, product, quantity, data):
- return SessionCartLine(product, quantity, data)
\ No newline at end of file
+ return SessionCartLine(product, quantity, data)
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.py
index 8a936a1960..3fb045c94e 100644
--- a/saleor/checkout/steps.py
+++ b/saleor/checkout/steps.py
@@ -145,12 +145,11 @@ class ShippingStep(BaseAddressStep):
def __init__(self, request, storage, purchased_items, _id=None,
default_address=None):
self.id = _id
- address_dict = storage.get('address', default_address)
- if not address_dict:
- address = Address()
- else:
- address = Address(**address_dict)
- super(ShippingStep, self).__init__(request, storage, address_dict)
+ address_data = storage.get('address', default_address)
+ if address_data is None:
+ address_data = {}
+ address = Address(**address_data)
+ super(ShippingStep, self).__init__(request, storage, address_data)
delivery_choices = list(
get_delivery_choices_for_group(purchased_items, address=address))
selected_delivery_name = storage.get('delivery_method')