Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add first and last name in dashboard
fowczareka762ef67ca27
diff --git a/saleor/account/models.py b/saleor/account/models.pyindex e889e9da83..6fc30e4d1f 100644--- a/saleor/account/models.py+++ b/saleor/account/models.py@@ -108,6 +108,8 @@ def get_token():class User(PermissionsMixin, AbstractBaseUser):email = models.EmailField(unique=True)+ first_name = models.CharField(max_length=256, blank=True)+ last_name = models.CharField(max_length=256, blank=True)addresses = models.ManyToManyField(Address, blank=True, related_name='user_addresses')is_staff = models.BooleanField(default=False)@@ -139,6 +141,15 @@ class User(PermissionsMixin, AbstractBaseUser):'Permission description', 'Impersonate customers.')))def get_full_name(self):+ if self.first_name or self.last_name:+ not_empty_names = filter(None, [self.first_name, self.last_name])+ return ' '.join(not_empty_names)+ if self.default_billing_address:+ not_empty_names = list(filter(None, [+ self.default_billing_address.first_name,+ self.default_billing_address.last_name]))+ if not_empty_names:+ return ' '.join(not_empty_names)return self.emaildef get_short_name(self):diff --git a/saleor/dashboard/customer/filters.py b/saleor/dashboard/customer/filters.pyindex fcd08e204c..3167a48a51 100644--- a/saleor/dashboard/customer/filters.py+++ b/saleor/dashboard/customer/filters.py@@ -9,7 +9,7 @@ from ...core.filters import SortedFilterSetSORT_BY_FIELDS = (('email', 'email'),- ('default_billing_address__first_name', 'name'),+ ('first_name', 'name'),('default_billing_address__city', 'location'))SORT_BY_FIELDS_LABELS = {@@ -27,7 +27,7 @@ IS_ACTIVE_CHOICES = (class UserFilter(SortedFilterSet):name_or_email = CharFilter(- label=pgettext_lazy('Customer name or email filter', 'Name or email'),+ label=pgettext_lazy('Customer name or email filter', 'Name or email'),method='filter_by_customer')location = CharFilter(label=pgettext_lazy('Customer list filter label', 'Location'),@@ -48,6 +48,8 @@ class UserFilter(SortedFilterSet):def filter_by_customer(self, queryset, name, value):return queryset.filter(+ Q(first_name__icontains=value) |+ Q(last_name__icontains=value) |Q(email__icontains=value) |Q(default_billing_address__first_name__icontains=value) |Q(default_billing_address__last_name__icontains=value))diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.pyindex e4926432dc..21ba9b6535 100644--- a/saleor/dashboard/customer/forms.py+++ b/saleor/dashboard/customer/forms.py@@ -4,6 +4,13 @@ from django.utils.translation import pgettext_lazyfrom ...account.models import CustomerNote, User+def get_name_placeholder(name):+ return pgettext_lazy(+ 'Customer form: Name field placeholder',+ '%(name)s (Inherit from default biling address)') % {+ 'name': name}++class CustomerDeleteForm(forms.Form):def __init__(self, *args, **kwargs):@@ -42,10 +49,24 @@ class CustomerForm(forms.ModelForm):self.fields['is_active'].disabled = Trueself.fields['note'].disabled = True+ address = self.instance.default_billing_address+ if not address:+ return+ if address.first_name:+ placeholder = get_name_placeholder(address.first_name)+ self.fields['first_name'].widget.attrs['placeholder'] = placeholder+ if address.last_name:+ placeholder = get_name_placeholder(address.last_name)+ self.fields['last_name'].widget.attrs['placeholder'] = placeholder+class Meta:model = User- fields = ['email', 'is_active', 'note']+ fields = ['first_name', 'last_name', 'email', 'is_active', 'note']labels = {+ 'first_name': pgettext_lazy(+ 'Customer form: Given name field', 'Given name'),+ 'last_name': pgettext_lazy(+ 'Customer form: Family name field', 'Family name'),'email': pgettext_lazy('Customer form: email address field', 'Email'),'is_active': pgettext_lazy(diff --git a/saleor/dashboard/staff/filters.py b/saleor/dashboard/staff/filters.pyindex b352a787c7..42630edf69 100644--- a/saleor/dashboard/staff/filters.py+++ b/saleor/dashboard/staff/filters.py@@ -8,7 +8,7 @@ from ..forms import PermissionMultipleChoiceFieldSORT_BY_FIELDS = (('email', 'email'),- ('default_billing_address__first_name', 'name'),+ ('first_name', 'name'),('default_billing_address__city', 'location'))SORT_BY_FIELDS_LABELS = {diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.pyindex 649e275ce4..fe93694dd8 100644--- a/saleor/dashboard/staff/forms.py+++ b/saleor/dashboard/staff/forms.py@@ -6,6 +6,13 @@ from ...core.permissions import get_permissionsfrom ..forms import PermissionMultipleChoiceField+def get_name_placeholder(name):+ return pgettext_lazy(+ 'Customer form: Name field placeholder',+ '%(name)s (Inherit from default biling address)') % {+ 'name': name}++class StaffForm(forms.ModelForm):user_permissions = PermissionMultipleChoiceField(queryset=get_permissions(),@@ -15,8 +22,13 @@ class StaffForm(forms.ModelForm):class Meta:model = User- fields = ['email', 'user_permissions', 'is_active']+ fields = ['first_name', 'last_name', 'email',+ 'user_permissions', 'is_active']labels = {+ 'first_name': pgettext_lazy(+ 'Customer form: Given name field', 'Given name'),+ 'last_name': pgettext_lazy(+ 'Customer form: Family name field', 'Family name'),'email': pgettext_lazy('Email', 'Email'),'is_active': pgettext_lazy(@@ -28,3 +40,13 @@ class StaffForm(forms.ModelForm):self.instance.is_staff = Trueif self.user == self.instance:self.fields['is_active'].disabled = True++ address = self.instance.default_billing_address+ if not address:+ return+ if address.first_name:+ placeholder = get_name_placeholder(address.first_name)+ self.fields['first_name'].widget.attrs['placeholder'] = placeholder+ if address.last_name:+ placeholder = get_name_placeholder(address.last_name)+ self.fields['last_name'].widget.attrs['placeholder'] = placeholderdiff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.htmlindex 968a667d45..ef20f9c414 100644--- a/templates/dashboard/customer/detail.html+++ b/templates/dashboard/customer/detail.html@@ -42,8 +42,13 @@<div class="card"><div class="card-content"><span class="card-title">- {{ customer.email }}+ {{ customer.get_full_name }}</span>+ {% if customer.get_full_name != customer.email %}+ <p>+ {{ customer.email }}+ </p>+ {% endif %}<div class="row">{% if customer.date_joined %}<div class="col s12 m4 l12">diff --git a/templates/dashboard/customer/list.html b/templates/dashboard/customer/list.htmlindex 6078b7977d..8077e8b1b1 100644--- a/templates/dashboard/customer/list.html+++ b/templates/dashboard/customer/list.html@@ -52,8 +52,8 @@<tr data-action-go="{% url "dashboard:customer-details" pk=customer.pk %}">{% with customer.default_billing_address as default_address %}<td>- {% if default_address %}- {{ default_address.first_name }} {{ default_address.last_name }}+ {% if customer.get_full_name != customer.email %}+ {{ customer.get_full_name }}{% else %}-{% endif %}diff --git a/templates/dashboard/staff/list.html b/templates/dashboard/staff/list.htmlindex 4c0da3f9ac..f6e407df5f 100644--- a/templates/dashboard/staff/list.html+++ b/templates/dashboard/staff/list.html@@ -54,8 +54,8 @@<tr data-action-go="{% url "dashboard:staff-details" pk=user.pk %}">{% with user.default_billing_address as default_address %}<td>- {% if default_address %}- {{ default_address.first_name }} {{ default_address.last_name }}+ {% if user.get_full_name != user.email %}+ {{ user.get_full_name }}{% else %}-{% endif %}