Skip to content

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

Improve contextual markers and translations for product app

Marco Badan23e872b928ef
diff --git a/saleor/product/forms.py b/saleor/product/forms.py
index 4db1ce4f4c..b8773377cd 100644
--- a/saleor/product/forms.py
+++ b/saleor/product/forms.py
@@ -15,11 +15,12 @@ class VariantChoiceField(forms.ModelChoiceField):
discounts = None
def label_from_instance(self, obj):
- attributes = obj.product.product_class.variant_attributes.all()
variant_label = smart_text(obj)
- label = '%(variant_label)s - %(price)s' % {
- 'variant_label': variant_label,
- 'price': gross(obj.get_price(discounts=self.discounts))}
+ label = pgettext_lazy(
+ 'Variant choice field label',
+ '%(variant_label)s - %(price)s') % {
+ 'variant_label': variant_label,
+ 'price': gross(obj.get_price(discounts=self.discounts))}
return label
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.py
index 220deaf915..53e96ca0db 100644
--- a/saleor/product/models/base.py
+++ b/saleor/product/models/base.py
@@ -50,6 +50,11 @@ class Category(MPTTModel):
objects = CategoryManager()
tree = TreeManager()
+ class Meta:
+ verbose_name = pgettext_lazy('Category model', 'category')
+ verbose_name_plural = pgettext_lazy('Category model', 'categories')
+ app_label = 'product'
+
def __str__(self):
return self.name
@@ -66,10 +71,6 @@ class Category(MPTTModel):
nodes = [node for node in ancestors] + [self]
return '/'.join([node.slug for node in nodes])
- class Meta:
- verbose_name_plural = 'categories'
- app_label = 'product'
-
def set_hidden_descendants(self, hidden):
self.get_descendants().update(hidden=hidden)
@@ -92,6 +93,10 @@ class ProductClass(models.Model):
default=False)
class Meta:
+ verbose_name = pgettext_lazy(
+ 'Product class model', 'product class')
+ verbose_name_plural = pgettext_lazy(
+ 'Product class model', 'product classes')
app_label = 'product'
def __str__(self):
@@ -117,7 +122,9 @@ class ProductManager(models.Manager):
@python_2_unicode_compatible
class Product(models.Model, ItemRange, index.Indexed):
- product_class = models.ForeignKey(ProductClass, related_name='products')
+ product_class = models.ForeignKey(
+ ProductClass, related_name='products',
+ verbose_name=pgettext_lazy('Product field', 'product class'))
name = models.CharField(
pgettext_lazy('Product field', 'name'), max_length=128)
description = models.TextField(
@@ -149,6 +156,8 @@ class Product(models.Model, ItemRange, index.Indexed):
class Meta:
app_label = 'product'
+ verbose_name = pgettext_lazy('Product model', 'product')
+ verbose_name_plural = pgettext_lazy('Product model', 'products')
def __iter__(self):
if not hasattr(self, '__variants'):
@@ -200,25 +209,29 @@ class Product(models.Model, ItemRange, index.Indexed):
@python_2_unicode_compatible
class ProductVariant(models.Model, Item):
sku = models.CharField(
- pgettext_lazy('Variant field', 'SKU'), max_length=32, unique=True)
+ pgettext_lazy('Product variant field', 'SKU'), max_length=32, unique=True)
name = models.CharField(
- pgettext_lazy('Variant field', 'variant name'), max_length=100,
+ pgettext_lazy('Product variant field', 'variant name'), max_length=100,
blank=True)
price_override = PriceField(
- pgettext_lazy('Variant field', 'price override'),
+ pgettext_lazy('Product variant field', 'price override'),
currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,
blank=True, null=True)
weight_override = WeightField(
- pgettext_lazy('Variant field', 'weight override'),
+ pgettext_lazy('Product variant field', 'weight override'),
unit=settings.DEFAULT_WEIGHT, max_digits=6, decimal_places=2,
blank=True, null=True)
product = models.ForeignKey(Product, related_name='variants')
attributes = HStoreField(
- pgettext_lazy('Variant field', 'attributes'), default={})
- images = models.ManyToManyField('ProductImage', through='VariantImage')
+ pgettext_lazy('Product variant field', 'attributes'), default={})
+ images = models.ManyToManyField(
+ 'ProductImage', through='VariantImage',
+ verbose_name=pgettext_lazy('Product variant field', 'images'))
class Meta:
app_label = 'product'
+ verbose_name = pgettext_lazy('Product variant model', 'product variant')
+ verbose_name_plural = pgettext_lazy('Product variant model', 'product variants')
def __str__(self):
return self.name or self.display_variant()
@@ -278,7 +291,7 @@ class ProductVariant(models.Model, Item):
if values:
return ', '.join(
['%s: %s' % (smart_text(attributes.get(id=int(key))),
- smart_text(value))
+ smart_text(value))
for (key, value) in six.iteritems(values)])
else:
return smart_text(self.sku)
@@ -308,7 +321,7 @@ class ProductVariant(models.Model, Item):
@python_2_unicode_compatible
class StockLocation(models.Model):
name = models.CharField(
- pgettext_lazy('Stock item field', 'location'), max_length=100)
+ pgettext_lazy('Stock location field', 'location'), max_length=100)
def __str__(self):
return self.name
@@ -371,7 +384,9 @@ class ProductAttribute(models.Model):
max_length=100)
class Meta:
- ordering = ['name']
+ ordering = ('name', )
+ verbose_name = pgettext_lazy('Product attribute model', 'product attribute')
+ verbose_name_plural = pgettext_lazy('Product attribute model', 'product attributes')
def __str__(self):
return self.display
@@ -396,5 +411,13 @@ class AttributeChoiceValue(models.Model):
blank=True)
attribute = models.ForeignKey(ProductAttribute, related_name='values')
+ class Meta:
+ verbose_name = pgettext_lazy(
+ 'Attribute choice value model',
+ 'attribute choices value')
+ verbose_name_plural = pgettext_lazy(
+ 'Attribute choice value model',
+ 'attribute choices values')
+
def __str__(self):
return self.display
diff --git a/saleor/product/models/images.py b/saleor/product/models/images.py
index bc589d1ca6..6c688f338a 100644
--- a/saleor/product/models/images.py
+++ b/saleor/product/models/images.py
@@ -17,20 +17,27 @@ class ImageManager(models.Manager):
class ProductImage(models.Model):
- product = models.ForeignKey(Product, related_name='images')
+ product = models.ForeignKey(
+ Product, related_name='images',
+ verbose_name=pgettext_lazy('Product image field', 'product'))
image = VersatileImageField(
- upload_to='products', ppoi_field='ppoi', blank=False)
- ppoi = PPOIField()
+ upload_to='products', ppoi_field='ppoi', blank=False,
+ verbose_name=pgettext_lazy('Product image field', 'image'))
+ ppoi = PPOIField(verbose_name=pgettext_lazy('Product image field', 'ppoi'))
alt = models.CharField(
pgettext_lazy('Product image field', 'short description'),
max_length=128, blank=True)
- order = models.PositiveIntegerField(editable=False)
+ order = models.PositiveIntegerField(
+ pgettext_lazy('Product image field', 'order'),
+ editable=False)
objects = ImageManager()
class Meta:
- ordering = ['order']
+ ordering = ('order', )
app_label = 'product'
+ verbose_name = pgettext_lazy('Product image model', 'product image')
+ verbose_name_plural = pgettext_lazy('Product image model', 'product images')
def get_ordering_queryset(self):
return self.product.images.all()
@@ -50,6 +57,15 @@ class ProductImage(models.Model):
class VariantImage(models.Model):
- variant = models.ForeignKey('ProductVariant',
- related_name='variant_images')
- image = models.ForeignKey(ProductImage, related_name='variant_images')
+ variant = models.ForeignKey(
+ 'ProductVariant', related_name='variant_images',
+ verbose_name=pgettext_lazy('Variant image field', 'variant'))
+ image = models.ForeignKey(
+ ProductImage, related_name='variant_images',
+ verbose_name=pgettext_lazy('Variant image field', 'image'))
+
+ class Meta:
+ verbose_name = pgettext_lazy(
+ 'Variant image model', 'variant image')
+ verbose_name_plural = pgettext_lazy(
+ 'Variant image model', 'variant images')
diff --git a/saleor/product/templatetags/product_images.py b/saleor/product/templatetags/product_images.py
index bf6ac4dad5..046b5ba7d6 100644
--- a/saleor/product/templatetags/product_images.py
+++ b/saleor/product/templatetags/product_images.py
@@ -26,7 +26,7 @@ def get_thumbnail(instance, size, method='crop'):
if instance:
size_name = '%s__%s' % (method, size)
if (size_name not in AVAILABLE_SIZES and not
- settings.VERSATILEIMAGEFIELD_SETTINGS['create_images_on_demand']):
+ settings.VERSATILEIMAGEFIELD_SETTINGS['create_images_on_demand']):
msg = ('Thumbnail size %s is not defined in settings '
'and it won\'t be generated automatically' % size_name)
warnings.warn(msg)