Skip to content

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

Improve contextual markers for checkout app

Marco Badana6a03c216c51
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.py
index 9d8b1ea963..9a7491b3d9 100644
--- a/saleor/checkout/forms.py
+++ b/saleor/checkout/forms.py
@@ -1,6 +1,6 @@
from django import forms
from django.utils.safestring import mark_safe
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import pgettext_lazy
from django_prices.templatetags.prices_i18n import format_price
from ..shipping.models import ShippingMethodCountry
@@ -15,10 +15,13 @@ class ShippingAddressesForm(forms.Form):
NEW_ADDRESS = 'new_address'
CHOICES = (
- (NEW_ADDRESS, _('Enter a new address')),
+ (NEW_ADDRESS, pgettext_lazy(
+ 'Shipping addresses form choice', 'Enter a new address')),
)
- address = CheckoutAddressField(choices=CHOICES, initial=NEW_ADDRESS)
+ address = CheckoutAddressField(
+ label=pgettext_lazy('Shipping addresses form field label', 'Address'),
+ choices=CHOICES, initial=NEW_ADDRESS)
def __init__(self, *args, **kwargs):
additional_addresses = kwargs.pop('additional_addresses', [])
@@ -34,8 +37,10 @@ class BillingAddressesForm(ShippingAddressesForm):
NEW_ADDRESS = 'new_address'
SHIPPING_ADDRESS = 'shipping_address'
CHOICES = (
- (NEW_ADDRESS, _('Enter a new address')),
- (SHIPPING_ADDRESS, _('Same as shipping'))
+ (NEW_ADDRESS, pgettext_lazy(
+ 'Billing addresses form choice', 'Enter a new address')),
+ (SHIPPING_ADDRESS, pgettext_lazy(
+ 'Billing addresses form choice', 'Same as shipping'))
)
address = CheckoutAddressField(choices=CHOICES, initial=SHIPPING_ADDRESS)
@@ -61,7 +66,8 @@ class ShippingMethodForm(forms.Form):
method = ShippingCountryChoiceField(
queryset=ShippingMethodCountry.objects.select_related(
'shipping_method').order_by('price').all(),
- label=_('Shipping method'), required=True)
+ label=pgettext_lazy('Shipping method form field label', 'Shipping method'),
+ required=True)
def __init__(self, country_code, *args, **kwargs):
super(ShippingMethodForm, self).__init__(*args, **kwargs)
@@ -77,10 +83,12 @@ class ShippingMethodForm(forms.Form):
class AnonymousUserShippingForm(forms.Form):
email = forms.EmailField(
- required=True, widget=forms.EmailInput(attrs={'autocomplete': 'shipping email'}))
+ required=True, widget=forms.EmailInput(attrs={'autocomplete': 'shipping email'}),
+ label=pgettext_lazy('Shipping form field label', 'Email'))
class AnonymousUserBillingForm(forms.Form):
email = forms.EmailField(
- required=True, widget=forms.EmailInput(attrs={'autocomplete': 'billing email'}))
+ required=True, widget=forms.EmailInput(attrs={'autocomplete': 'billing email'}),
+ label=pgettext_lazy('Billing form field label', 'Email'))
diff --git a/saleor/checkout/views/discount.py b/saleor/checkout/views/discount.py
index 2646350265..960f906cf6 100644
--- a/saleor/checkout/views/discount.py
+++ b/saleor/checkout/views/discount.py
@@ -50,7 +50,7 @@ def validate_voucher(view):
del checkout.voucher_code
checkout.recalculate_discount()
msg = pgettext(
- 'checkout warning',
+ 'Checkout warning',
'This voucher has expired. Please review your checkout.')
messages.warning(request, msg)
return redirect('checkout:summary')
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.py
index 217014a8f1..3571a87ad4 100644
--- a/saleor/checkout/views/summary.py
+++ b/saleor/checkout/views/summary.py
@@ -1,6 +1,7 @@
from django.contrib import messages
from django.shortcuts import redirect
from django.template.response import TemplateResponse
+from django.utils.translation import pgettext
from ..forms import (
AnonymousUserBillingForm, BillingAddressesForm,
@@ -23,7 +24,8 @@ def create_order(checkout):
def handle_order_placement(request, checkout):
order, success_redirect = create_order(checkout)
if not order:
- messages.warning(request, 'Please review your checkout.')
+ msg = pgettext('Checkout warning', 'Please review your checkout.')
+ messages.warning(request, msg)
return success_redirect