Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve contextual markers for userprofile app
Marco Badan802d026bf622
diff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.pyindex 327bb2fdac..fb185e5246 100644--- a/saleor/userprofile/forms.py+++ b/saleor/userprofile/forms.py@@ -4,7 +4,7 @@ from __future__ import unicode_literalsfrom allauth.account.adapter import get_adapterfrom allauth.account.forms import SetPasswordField, UserForm, PasswordFieldfrom django import forms-from django.utils.translation import ugettext_lazy as _+from django.utils.translation import pgettextfrom .i18n import AddressMetaForm, get_address_form_class@@ -37,7 +37,8 @@ def get_address_form(data, country_code, initial=None, instance=None, **kwargs):class SetPasswordForm(forms.Form):- password1 = SetPasswordField(label=_('New Password'))+ password1 = SetPasswordField(+ label=pgettext('Set password form label', 'New Password'))def __init__(self, *args, **kwargs):self.user = kwargs.pop('user', None)@@ -51,8 +52,10 @@ class SetPasswordForm(forms.Form):class ChangePasswordForm(UserForm):- oldpassword = PasswordField(label=_('Current Password'))- password1 = SetPasswordField(label=_('New Password'))+ oldpassword = PasswordField(+ label=pgettext('Change password form label', 'Current Password'))+ password1 = SetPasswordField(+ label=pgettext('Change password form label', 'New Password'))def __init__(self, *args, **kwargs):super(ChangePasswordForm, self).__init__(*args, **kwargs)@@ -62,8 +65,10 @@ class ChangePasswordForm(UserForm):def clean_oldpassword(self):if not self.user.check_password(self.cleaned_data.get('oldpassword')):- raise forms.ValidationError(_('Please type your current'- ' password.'))+ raise forms.ValidationError(+ pgettext(+ 'Change password form error',+ 'Please type your current password.'))return self.cleaned_data['oldpassword']def save(self):diff --git a/saleor/userprofile/i18n.py b/saleor/userprofile/i18n.pyindex 5f16b5b209..01d801b8e4 100644--- a/saleor/userprofile/i18n.py+++ b/saleor/userprofile/i18n.py@@ -3,7 +3,7 @@ from collections import defaultdictimport i18naddressfrom django import formsfrom django.forms.forms import BoundField-from django.utils.translation import pgettext_lazy+from django.utils.translation import pgettext_lazy, pgettextfrom django_countries.data import COUNTRIESfrom .models import Address@@ -35,7 +35,9 @@ AREA_TYPE_TRANSLATIONS = {class AddressMetaForm(forms.ModelForm):- preview = forms.BooleanField(initial=False, required=False)+ preview = forms.BooleanField(+ label=pgettext('Address meta form label', 'preview'),+ initial=False, required=False)class Meta:model = Addressdiff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex 0adef2b9cc..832130ceca 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -70,6 +70,10 @@ class Address(models.Model):def full_name(self):return '%s %s' % (self.first_name, self.last_name)+ class Meta:+ verbose_name = pgettext_lazy('Address model', 'address')+ verbose_name_plural = pgettext_lazy('Address model', 'addresses')+def __str__(self):if self.company_name:return '%s - %s' % (self.company_name, self.full_name)@@ -105,8 +109,10 @@ class UserManager(BaseUserManager):class User(PermissionsMixin, AbstractBaseUser, index.Indexed):- email = models.EmailField(unique=True)- addresses = models.ManyToManyField(Address, blank=True)+ email = models.EmailField(pgettext_lazy('User field', 'email'), unique=True)+ addresses = models.ManyToManyField(+ Address, blank=True,+ verbose_name=pgettext_lazy('User field', 'addresses'))is_staff = models.BooleanField(pgettext_lazy('User field', 'staff status'),default=False)@@ -132,6 +138,10 @@ class User(PermissionsMixin, AbstractBaseUser, index.Indexed):search_fields = [index.SearchField('email')]+ class Meta:+ verbose_name = pgettext_lazy('User model', 'user')+ verbose_name_plural = pgettext_lazy('User model', 'users')+def get_full_name(self):return self.emaildiff --git a/saleor/userprofile/templatetags/__init__.py b/saleor/userprofile/templatetags/__init__.pyindex 8b13789179..e69de29bb2 100644--- a/saleor/userprofile/templatetags/__init__.py+++ b/saleor/userprofile/templatetags/__init__.py@@ -1 +0,0 @@-diff --git a/saleor/userprofile/templatetags/i18n_address_tags.py b/saleor/userprofile/templatetags/i18n_address_tags.pyindex a3d8d305a4..060d2f16df 100644--- a/saleor/userprofile/templatetags/i18n_address_tags.py+++ b/saleor/userprofile/templatetags/i18n_address_tags.py@@ -1,6 +1,8 @@from django import template-import i18naddressfrom django.utils.safestring import mark_safe+from django.utils.translation import pgettext+import i18naddress+from ...userprofile.models import Addressregister = template.Library()@@ -9,9 +11,12 @@ register = template.Library()@register.simple_tagdef format_address(address, latin=False):address_data = Address.objects.as_data(address)- address_data['name'] = '%(first_name)s %(last_name)s' % address_data+ address_data['name'] = pgettext(+ 'Address data', '%(first_name)s %(last_name)s') % address_dataaddress_data['country_code'] = address_data['country']- address_data['street_address'] = ('%(street_address_1)s\n'- '%(street_address_2)s' % address_data)+ address_data['street_address'] = pgettext(+ 'Address data',+ '%(street_address_1)s\n'+ '%(street_address_2)s' % address_data)formatted_address = i18naddress.format_address(address_data, latin)return mark_safe(formatted_address)diff --git a/saleor/userprofile/views.py b/saleor/userprofile/views.pyindex a794b8e9bd..0ee7d2b197 100755--- a/saleor/userprofile/views.py+++ b/saleor/userprofile/views.py@@ -8,7 +8,7 @@ from django.core.urlresolvers import reversefrom django.http import HttpResponseRedirectfrom django.shortcuts import get_object_or_404from django.template.response import TemplateResponse-from django.utils.translation import ugettext as _+from django.utils.translation import pgettextfrom ..cart.utils import find_and_assign_anonymous_cartfrom .forms import ChangePasswordForm, get_address_form@@ -43,19 +43,22 @@ def address_edit(request, pk):country_code=address.country.code)if address_form.is_valid() and not preview:address_form.save()- message = _('Address successfully updated.')+ message = pgettext('Storefront message', 'Address successfully updated.')messages.success(request, message)return HttpResponseRedirect(reverse('profile:details'))return TemplateResponse(request, 'userprofile/address-edit.html',{'address_form': address_form})+@login_requireddef address_delete(request, pk):address = get_object_or_404(request.user.addresses, pk=pk)if request.method == 'POST':address.delete()- messages.success(request, _('Address successfully deleted.'))+ messages.success(+ request,+ pgettext('Storefront message', 'Address successfully deleted.'))return HttpResponseRedirect(reverse('profile:details') + '#addresses')return TemplateResponse(request, 'userprofile/address-delete.html', {'address': address})