Skip to content

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

Translation and code style fixed

Artur Smęt83cda9582d18
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.py
index 7013b004d7..cf9257f215 100644
--- a/saleor/cart/forms.py
+++ b/saleor/cart/forms.py
@@ -9,6 +9,7 @@ from satchless.item import InsufficientStock
class QuantityField(forms.DecimalField):
+
def __init__(self, *args, **kwargs):
super(QuantityField, self).__init__(
*args, max_value=None, min_value=Decimal(0), max_digits=10,
@@ -16,16 +17,21 @@ class QuantityField(forms.DecimalField):
class AddToCartForm(forms.Form):
- '''
+ """
Class use product and cart instance.
- '''
+ """
quantity = QuantityField(label=pgettext('Form field', 'Quantity'))
error_messages = {
- 'empty-stock': ugettext('Sorry. This product is unavailable'),
+ 'empty-stock': ugettext(
+ 'Sorry. This product is currently out of stock'
+ ),
'variant-does-not-exists': ugettext(
- 'Oops. We could not find that product.'),
+ 'Oops. We could not find that product.'
+ ),
'insufficient-stock': ugettext(
- 'Only %(remaining)d remaining in stock.')}
+ 'Only %(remaining)d remaining in stock.'
+ )
+ }
def __init__(self, *args, **kwargs):
self.cart = kwargs.pop('cart')
@@ -35,32 +41,33 @@ class AddToCartForm(forms.Form):
def clean(self):
cleaned_data = super(AddToCartForm, self).clean()
quantity = cleaned_data.get('quantity')
- if quantity is not None:
+ if quantity is None:
+ return cleaned_data
+ try:
+ product_variant = self.get_variant(cleaned_data)
+ except ObjectDoesNotExist:
+ msg = self.error_messages['variant-does-not-exists']
+ self.add_error(NON_FIELD_ERRORS, msg)
+ else:
+ cart_line = self.cart.get_line(product_variant)
+ used_quantity = cart_line.quantity if cart_line else 0
+ new_quantity = quantity + used_quantity
try:
- product_variant = self.get_variant(cleaned_data)
- except ObjectDoesNotExist:
- msg = self.error_messages['variant-does-not-exists']
- self.add_error(NON_FIELD_ERRORS, msg)
- else:
- cart_line = self.cart.get_line(product_variant)
- used_quantity = cart_line.quantity if cart_line else 0
- new_quantity = quantity + used_quantity
- try:
- self.cart.check_quantity(
- product_variant, new_quantity, None)
- except InsufficientStock as e:
- remaining = e.item.stock - used_quantity
- if remaining:
- msg = self.error_messages['insufficient-stock']
- else:
- msg = self.error_messages['empty-stock']
- self.add_error('quantity', msg % {'remaining': remaining})
+ self.cart.check_quantity(
+ product_variant, new_quantity, None)
+ except InsufficientStock as e:
+ remaining = e.item.stock - used_quantity
+ if remaining:
+ msg = self.error_messages['insufficient-stock']
+ else:
+ msg = self.error_messages['empty-stock']
+ self.add_error('quantity', msg % {'remaining': remaining})
return cleaned_data
def save(self):
- '''
+ """
Adds CartLine into the Cart instance.
- '''
+ """
product_variant = self.get_variant(self.cleaned_data)
return self.cart.add(product_variant, self.cleaned_data['quantity'])
@@ -73,10 +80,9 @@ class AddToCartForm(forms.Form):
class ReplaceCartLineForm(AddToCartForm):
- '''
+ """
Replaces quantity in CartLine.
- '''
-
+ """
def __init__(self, *args, **kwargs):
super(ReplaceCartLineForm, self).__init__(*args, **kwargs)
self.cart_line = self.cart.get_line(self.product)
@@ -91,21 +97,21 @@ class ReplaceCartLineForm(AddToCartForm):
return quantity
def get_variant(self, cleaned_data):
- 'In cart formset product is already variant'
+ """In cart formset product is already variant"""
return self.product
def save(self):
- '''
+ """
Replace quantity.
- '''
+ """
return self.cart.add(self.product, self.cleaned_data['quantity'],
replace=True)
class ReplaceCartLineFormSet(BaseFormSet):
- '''
+ """
Formset for all CartLines in the cart instance.
- '''
+ """
absolute_max = 9999
can_delete = False
can_order = False
diff --git a/saleor/product/models/__init__.py b/saleor/product/models/__init__.py
index 296937e0d2..849b11b5e9 100644
--- a/saleor/product/models/__init__.py
+++ b/saleor/product/models/__init__.py
@@ -2,7 +2,7 @@ from .base_products import Category, Product
from .discounts import FixedProductDiscount, get_product_discounts
from .products import Bag, BagVariant, Shirt, ShirtVariant
from .variants import (Color, ColoredVariant, StockedProduct, PhysicalProduct,
- ProductVariant)
+ ProductVariant)
from .images import ProductImage
__all__ = ['Category', 'Product', 'FixedProductDiscount',
diff --git a/saleor/product/models/base_products.py b/saleor/product/models/base_products.py
index 2a4d9d0e97..bb17ea76a2 100644
--- a/saleor/product/models/base_products.py
+++ b/saleor/product/models/base_products.py
@@ -76,6 +76,7 @@ class Product(Subtyped, ItemRange):
def admin_get_price_min(self):
price = self.get_price_range().min_price
return self.get_formatted_price(price)
+
admin_get_price_min.short_description = pgettext_lazy(
'Product admin page', 'Minimal price'
)
@@ -83,6 +84,7 @@ class Product(Subtyped, ItemRange):
def admin_get_price_max(self):
price = self.get_price_range().max_price
return self.get_formatted_price(price)
+
admin_get_price_max.short_description = pgettext_lazy(
'Product admin page', 'Maximal price'
)
\ No newline at end of file
diff --git a/saleor/product/models/images.py b/saleor/product/models/images.py
index d4af7291c3..6620cffeb0 100644
--- a/saleor/product/models/images.py
+++ b/saleor/product/models/images.py
@@ -4,6 +4,7 @@ from django.db import models
from django_images.models import Image
from django.utils.safestring import mark_safe
from django.utils.encoding import python_2_unicode_compatible
+
from .base_products import Product
diff --git a/saleor/product/models/products.py b/saleor/product/models/products.py
index 2913a8eb37..036b869c86 100644
--- a/saleor/product/models/products.py
+++ b/saleor/product/models/products.py
@@ -9,16 +9,19 @@ from .variants import (ProductVariant, PhysicalProduct, ColoredVariant,
class Bag(Product, PhysicalProduct, ColoredVariant):
+
class Meta:
app_label = 'product'
class Shirt(Product, PhysicalProduct, ColoredVariant):
+
class Meta:
app_label = 'product'
class BagVariant(ProductVariant, StockedProduct):
+
product = models.ForeignKey(Bag, related_name='variants')
class Meta:
@@ -26,6 +29,7 @@ class BagVariant(ProductVariant, StockedProduct):
class ShirtVariant(ProductVariant, StockedProduct):
+
SIZE_CHOICES = (
('xs', pgettext_lazy('Variant size', 'XS')),
('s', pgettext_lazy('Variant size', 'S')),