Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve UI and translations
Patryk Zawadzki53906dc79940
diff --git a/.editorconfig b/.editorconfigindex edab84c941..0cd5e5a0e7 100644--- a/.editorconfig+++ b/.editorconfig@@ -18,5 +18,8 @@ indent_size = 2[*.jsx]indent_size = 2+[*.scss]+indent_size = 2+[*.yml]indent_size = 2diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex f06bd3a320..5d3a04c5bd 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -2,7 +2,7 @@ import uuidfrom django import formsfrom django.conf import settings-from django.utils.translation import pgettext_lazy, gettext as _+from django.utils.translation import pgettext_lazyfrom django_prices.forms import PriceFieldfrom ...discount.models import Sale, Voucher@@ -28,13 +28,13 @@ class SaleForm(forms.ModelForm):class VoucherForm(forms.ModelForm):- ALL_BASKETS = 'all_baskets'+ ALL_PURCHASES = 'all_purchases'DISCOUNT_TYPES = (- (ALL_BASKETS, 'All baskets'),+ (ALL_PURCHASES, pgettext_lazy('voucher', 'All purchases')),) + Voucher.TYPE_CHOICEStype = forms.ChoiceField(- choices=DISCOUNT_TYPES, initial=ALL_BASKETS,- label=pgettext_lazy('voucher_form', 'Discount for'))+ choices=DISCOUNT_TYPES, initial=ALL_PURCHASES,+ label=pgettext_lazy('voucher', 'Discount for'))class Meta:model = Voucher@@ -43,8 +43,9 @@ class VoucherForm(forms.ModelForm):def __init__(self, *args, **kwargs):initial = kwargs.get('initial', {})instance = kwargs.get('instance')- if instance and instance.type == Voucher.BASKET_TYPE and instance.limit is None:- initial['type'] = VoucherForm.ALL_BASKETS+ if (instance and instance.type == Voucher.VALUE_TYPE and+ instance.limit is None):+ initial['type'] = VoucherForm.ALL_PURCHASESif instance and instance.id is None and not initial.get('code'):initial['code'] = self._generate_codekwargs['initial'] = initial@@ -58,8 +59,8 @@ class VoucherForm(forms.ModelForm):def clean(self):cleaned_data = super(VoucherForm, self).clean()- if cleaned_data['type'] == VoucherForm.ALL_BASKETS:- cleaned_data['type'] = Voucher.BASKET_TYPE+ if cleaned_data['type'] == VoucherForm.ALL_PURCHASES:+ cleaned_data['type'] = Voucher.VALUE_TYPEreturn cleaned_data@@ -71,7 +72,8 @@ class CountriesField(forms.ChoiceField):country_codes = country_codes.distinct()country_dict = dict(ShippingMethodCountry.COUNTRY_CODE_CHOICES)kwargs['choices'] = [- (country_code, country_dict[country_code]) for country_code in country_codes]+ (country_code, country_dict[country_code])+ for country_code in country_codes]super(CountriesField, self).__init__(*args, **kwargs)@@ -79,9 +81,9 @@ class ShippingVoucherForm(forms.ModelForm):limit = PriceField(min_value=0, required=False, currency=settings.DEFAULT_CURRENCY,- label=pgettext_lazy('voucher_form', 'Shipping cost equal or less than'),- help_text=pgettext_lazy('voucher_form', 'Any shipping if empty'))- apply_to = CountriesField(label='Country')+ label=pgettext_lazy(+ 'voucher', 'Only if shipping cost is less than or equal to'))+ apply_to = CountriesField(label=pgettext_lazy('voucher', 'Country'))class Meta:model = Voucher@@ -93,11 +95,12 @@ class ShippingVoucherForm(forms.ModelForm):return super(ShippingVoucherForm, self).save(commit)-class BasketVoucherForm(forms.ModelForm):+class ValueVoucherForm(forms.ModelForm):limit = PriceField(- min_value=0, required=True, currency = settings.DEFAULT_CURRENCY,- label=pgettext_lazy('voucher_form', 'Basket total equal or greater than'))+ min_value=0, required=True, currency=settings.DEFAULT_CURRENCY,+ label=pgettext_lazy(+ 'voucher', 'Purchase value greater than or equal to'))class Meta:model = Voucher@@ -107,7 +110,7 @@ class BasketVoucherForm(forms.ModelForm):self.instance.category = Noneself.instance.limit = Noneself.instance.product = None- return super(BasketVoucherForm, self).save(commit)+ return super(ValueVoucherForm, self).save(commit)class ProductVoucherForm(forms.ModelForm):diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.pyindex 3db73c01aa..e6948bf22f 100644--- a/saleor/dashboard/discount/views.py+++ b/saleor/dashboard/discount/views.py@@ -4,6 +4,7 @@ from django.contrib.admin.views.decorators import staff_member_requiredfrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import ugettext_lazy as _+from ...discount.models import Sale, Voucherfrom . import forms@@ -49,22 +50,30 @@ def sale_delete(request, pk):def voucher_list(request):vouchers = Voucher.objects.select_related('product', 'category')ctx = {'vouchers': vouchers}- return TemplateResponse(request, 'dashboard/discount/voucher_list.html', ctx)+ return TemplateResponse(+ request, 'dashboard/discount/voucher_list.html', ctx)@staff_member_requireddef voucher_edit(request, pk=None):- instance = get_object_or_404(Voucher, pk=pk) if pk is not None else Voucher()+ if pk is not None:+ instance = get_object_or_404(Voucher, pk=pk)+ else:+ instance = Voucher()voucher_form = forms.VoucherForm(request.POST or None, instance=instance)type_base_forms = {Voucher.SHIPPING_TYPE: forms.ShippingVoucherForm(- request.POST or None, instance=instance, prefix=Voucher.SHIPPING_TYPE),- Voucher.BASKET_TYPE: forms.BasketVoucherForm(- request.POST or None, instance=instance, prefix=Voucher.BASKET_TYPE),+ request.POST or None, instance=instance,+ prefix=Voucher.SHIPPING_TYPE),+ Voucher.VALUE_TYPE: forms.ValueVoucherForm(+ request.POST or None, instance=instance,+ prefix=Voucher.VALUE_TYPE),Voucher.PRODUCT_TYPE: forms.ProductVoucherForm(- request.POST or None, instance=instance, prefix=Voucher.PRODUCT_TYPE),+ request.POST or None, instance=instance,+ prefix=Voucher.PRODUCT_TYPE),Voucher.CATEGORY_TYPE: forms.CategoryVoucherForm(- request.POST or None, instance=instance, prefix=Voucher.CATEGORY_TYPE),+ request.POST or None, instance=instance,+ prefix=Voucher.CATEGORY_TYPE),}if voucher_form.is_valid():voucher_type = voucher_form.cleaned_data['type']@@ -81,7 +90,8 @@ def voucher_edit(request, pk=None):ctx = {'voucher': instance, 'default_currency': settings.DEFAULT_CURRENCY,'form': voucher_form, 'type_base_forms': type_base_forms}- return TemplateResponse(request, 'dashboard/discount/voucher_form.html', ctx)+ return TemplateResponse(+ request, 'dashboard/discount/voucher_form.html', ctx)@staff_member_requireddiff --git a/saleor/dashboard/templates/dashboard/discount/voucher_form.html b/saleor/dashboard/templates/dashboard/discount/voucher_form.htmlindex 2ecd6c4b8d..8f3ec341fd 100644--- a/saleor/dashboard/templates/dashboard/discount/voucher_form.html+++ b/saleor/dashboard/templates/dashboard/discount/voucher_form.html@@ -54,7 +54,6 @@<div class="col s12 l8"><div class="row">{{ form.code|materializecss }}- {{ form.usage_limit|materializecss }}{{ form.name|materializecss }}{{ form.discount_value|materializecss:"s12 m8" }}{{ form.discount_value_type|materializecss:"s12 m4" }}@@ -73,6 +72,7 @@<div class="row">{{ form.start_date|materializecss:"input-field s12" }}{{ form.end_date|materializecss:"input-field s12" }}+ {{ form.usage_limit|materializecss }}</div></div></div>diff --git a/saleor/dashboard/templates/materializecssform/field.html b/saleor/dashboard/templates/materializecssform/field.htmlindex 4ae4d55f16..e050730e8d 100644--- a/saleor/dashboard/templates/materializecssform/field.html+++ b/saleor/dashboard/templates/materializecssform/field.html@@ -52,7 +52,8 @@{% elif field|is_date_input %}<div class="input col {{ classes.label }}">- <label for="{{ field.id_for_label }}">{{ field.label }}</label>+ <label class="active{% if not field.field.required %} optional{% endif %}"+ for="{{ field.auto_id }}">{{ field.label }}</label><input type="date" id="{{ field.auto_id }}" class="datepicker"name="{{ field.name }}"value="{% if field.value %}{{ field.value }}{% endif %}"diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex cbed7eb764..4dd7b0accb 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -4,12 +4,10 @@ from decimal import Decimalfrom django.conf import settingsfrom django.db import models-from django.utils.safestring import mark_safe-from django.utils.translation import pgettext_lazy, gettext as _+from django.utils.translation import pgettext, pgettext_lazyfrom django.utils.encoding import python_2_unicode_compatiblefrom django_countries import countriesfrom django_prices.models import PriceField-from django_prices.templatetags.prices import grossfrom prices import FixedDiscount, percentage_discount, Price@@ -25,43 +23,50 @@ class Voucher(models.Model):APPLY_TO_PRODUCT_CHOICES = ((APPLY_TO_ONE_PRODUCT,- pgettext_lazy('voucher_form', 'Apply only once')),+ pgettext_lazy('voucher', 'Apply to a single item')),(APPLY_TO_ALL_PRODUCTS,- pgettext_lazy('voucher_form', 'Apply to all matching products')))+ pgettext_lazy('voucher', 'Apply to all matching products')))DISCOUNT_VALUE_FIXED = 'fixed'DISCOUNT_VALUE_PERCENTAGE = 'percentage'DISCOUNT_VALUE_TYPE_CHOICES = (- (DISCOUNT_VALUE_FIXED, pgettext_lazy('voucher_model', settings.DEFAULT_CURRENCY)), # noqa- (DISCOUNT_VALUE_PERCENTAGE, pgettext_lazy('voucher_model', '%')))+ (DISCOUNT_VALUE_FIXED,+ pgettext_lazy('voucher', settings.DEFAULT_CURRENCY)), # noqa+ (DISCOUNT_VALUE_PERCENTAGE, pgettext_lazy('voucher', '%')))PRODUCT_TYPE = 'product'CATEGORY_TYPE = 'category'SHIPPING_TYPE = 'shipping'- BASKET_TYPE = 'basket'+ VALUE_TYPE = 'value'TYPE_CHOICES = (- (PRODUCT_TYPE, pgettext_lazy('voucher_model', 'Product')),- (CATEGORY_TYPE, pgettext_lazy('voucher_model', 'Category')),- (SHIPPING_TYPE, pgettext_lazy('voucher_model', 'Shipping')),- (BASKET_TYPE, pgettext_lazy('voucher_model', 'Baskets over'))- )+ (PRODUCT_TYPE, pgettext_lazy('voucher', 'One product')),+ (CATEGORY_TYPE, pgettext_lazy('voucherl', 'Category of products')),+ (SHIPPING_TYPE, pgettext_lazy('voucher', 'Shipping')),+ (VALUE_TYPE, pgettext_lazy('voucher', 'Purchases over certain value')))type = models.CharField(max_length=20, choices=TYPE_CHOICES)- name = models.CharField(max_length=255, null=True, blank=True)- code = models.CharField(max_length=12, unique=True, db_index=True)+ name = models.CharField(+ pgettext_lazy('voucher', 'name'), max_length=255, null=True,+ blank=True)+ code = models.CharField(+ pgettext_lazy('voucher', 'code'), max_length=12, unique=True,+ db_index=True)usage_limit = models.PositiveIntegerField(- null=True, blank=True,- help_text=pgettext_lazy('voucher_model', 'Unlimited if empty'))+ pgettext_lazy('voucher', 'usage limit'), null=True, blank=True)used = models.PositiveIntegerField(default=0, editable=False)- start_date = models.DateField(default=date.today)- end_date = models.DateField(null=True, blank=True, help_text=pgettext_lazy(- 'voucher_model', 'Never expire if empty'))+ start_date = models.DateField(+ pgettext_lazy('voucher', 'start date'), default=date.today)+ end_date = models.DateField(+ pgettext_lazy('voucher', 'end date'), null=True, blank=True)discount_value_type = models.CharField(- max_length=10, choices=DISCOUNT_VALUE_TYPE_CHOICES, default=DISCOUNT_VALUE_FIXED)- discount_value = models.DecimalField(max_digits=12, decimal_places=2)+ pgettext_lazy('voucher', 'discount type'), max_length=10,+ choices=DISCOUNT_VALUE_TYPE_CHOICES, default=DISCOUNT_VALUE_FIXED)+ discount_value = models.DecimalField(+ pgettext_lazy('voucher', 'discount value'), max_digits=12,+ decimal_places=2)# not mandatory fields, usage depends on typeproduct = models.ForeignKey('product.Product', blank=True, null=True)@@ -72,8 +77,8 @@ class Voucher(models.Model):@propertydef is_free(self):- return (self.discount_value == Decimal(100)- and self.discount_value_type == Voucher.DISCOUNT_VALUE_PERCENTAGE)+ return (self.discount_value == Decimal(100) and+ self.discount_value_type == Voucher.DISCOUNT_VALUE_PERCENTAGE)def __str__(self):if self.name:@@ -82,24 +87,25 @@ class Voucher(models.Model):self.discount_value, self.get_discount_value_type_display())if self.type == Voucher.SHIPPING_TYPE:if self.is_free:- return _('Free shipping')+ return pgettext('voucher', 'Free shipping')else:- return _('%(discount)s off shipping') % {'discount': discount}+ return pgettext('voucher', '%(discount)s off shipping') % {+ 'discount': discount}if self.type == Voucher.PRODUCT_TYPE:- return _('%(discount)s off %(product)s') % {+ return pgettext('voucher', '%(discount)s off %(product)s') % {'discount': discount, 'product': self.product}if self.type == Voucher.CATEGORY_TYPE:- return _('%(discount)s off %(category)s') % {+ return pgettext('voucher', '%(discount)s off %(category)s') % {'discount': discount, 'category': self.category}- return _('%(discount)s off') % {'discount': discount}-+ return pgettext('voucher', '%(discount)s off') % {'discount': discount}def get_apply_to_display(self):if self.type == Voucher.SHIPPING_TYPE and self.apply_to:return countries.name(self.apply_to)if self.type == Voucher.SHIPPING_TYPE:- return _('Any country')- if self.apply_to and self.type in (Voucher.PRODUCT_TYPE, Voucher.CATEGORY_TYPE):+ return pgettext('voucher', 'Any country')+ if self.apply_to and self.type in {+ Voucher.PRODUCT_TYPE, Voucher.CATEGORY_TYPE}:choices = dict(self.APPLY_TO_PRODUCT_CHOICES)return choices[self.apply_to]diff --git a/saleor/static/scss/widget/_form.scss b/saleor/static/scss/widget/_form.scssindex 6d1bc38f67..16956f5e88 100644--- a/saleor/static/scss/widget/_form.scss+++ b/saleor/static/scss/widget/_form.scss@@ -90,12 +90,18 @@}}- &#form-discounts {+ &#form-sales {#id_name {@extend %input-lg;}}+ &#form-vouchers {+ #id_code {+ @extend %input-lg;+ }+ }+.sizedimage-mod {margin-bottom: $gutter-width/2;