Skip to content

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

Inherit getting filter set summary message

Anna Siwik029a4794e8bc
diff --git a/saleor/dashboard/category/filters.py b/saleor/dashboard/category/filters.py
index 973f959247..15c32e4899 100644
--- a/saleor/dashboard/category/filters.py
+++ b/saleor/dashboard/category/filters.py
@@ -1,4 +1,4 @@
-from django.utils.translation import pgettext_lazy
+from django.utils.translation import npgettext, pgettext_lazy
from django_filters import CharFilter, OrderingFilter
from ...core.filters import SortedFilterSet
@@ -27,3 +27,11 @@ class CategoryFilter(SortedFilterSet):
class Meta:
model = Category
fields = []
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard categories list',
+ 'Found %(counter)d matching category',
+ 'Found %(counter)d matching categories',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 825b6cd850..b9c1403d90 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -5,7 +5,7 @@ from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.urls import reverse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
from ...product.models import Category
@@ -22,16 +22,9 @@ def category_list(request):
categories = get_paginator_items(
category_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = category_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard categories list',
- 'Found %(counter)d matching category',
- 'Found %(counter)d matching categories',
- number=counter) % {'counter': counter}
ctx = {
'categories': categories, 'filter': category_filter,
- 'is_empty': not category_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not category_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/category/list.html', ctx)
@@ -96,14 +89,8 @@ def category_detail(request, pk):
categories = get_paginator_items(
category_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = category_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard subcategories list',
- 'Found %(counter)d matching subcategory',
- 'Found %(counter)d matching subcategories',
- number=counter) % {'counter': counter}
ctx = {'categories': categories, 'path': path, 'root': root,
- 'filter': category_filter, 'summary_msg': summary_msg,
+ 'filter': category_filter,
'is_empty': not category_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
diff --git a/saleor/dashboard/customer/filters.py b/saleor/dashboard/customer/filters.py
index b3ed86b539..7ae3daced3 100644
--- a/saleor/dashboard/customer/filters.py
+++ b/saleor/dashboard/customer/filters.py
@@ -1,8 +1,7 @@
from django import forms
from django.db.models import Q
-from django.utils.translation import pgettext_lazy
-from django_filters import (
- CharFilter, ChoiceFilter, OrderingFilter)
+from django.utils.translation import npgettext, pgettext_lazy
+from django_filters import CharFilter, ChoiceFilter, OrderingFilter
from django_countries import countries
from ...core.filters import SortedFilterSet
@@ -68,3 +67,11 @@ class UserFilter(SortedFilterSet):
if value.lower() in country.lower():
country_codes.append(code)
return country_codes
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard customers list',
+ 'Found %(counter)d matching customer',
+ 'Found %(counter)d matching customers',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index 99c42ea166..17f967a326 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -1,10 +1,9 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
-from django.db.models import Count, Max
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
from ...userprofile.models import User
@@ -24,16 +23,9 @@ def customer_list(request):
customers = get_paginator_items(
customer_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = customer_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard customers list',
- 'Found %(counter)d matching customer',
- 'Found %(counter)d matching customers',
- number=counter) % {'counter': counter}
ctx = {
'customers': customers, 'filter': customer_filter,
- 'is_empty': not customer_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not customer_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/customer/list.html', ctx)
diff --git a/saleor/dashboard/discount/filters.py b/saleor/dashboard/discount/filters.py
index fc7d3d667c..6f3cd11704 100644
--- a/saleor/dashboard/discount/filters.py
+++ b/saleor/dashboard/discount/filters.py
@@ -1,6 +1,6 @@
from django import forms
from django.db.models import Q
-from django.utils.translation import pgettext_lazy
+from django.utils.translation import pgettext_lazy, npgettext
from django_filters import (
CharFilter, ChoiceFilter, DateFromToRangeFilter, ModelMultipleChoiceFilter,
OrderingFilter, RangeFilter)
@@ -53,6 +53,14 @@ class SaleFilter(SortedFilterSet):
model = Sale
fields = []
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard sales list',
+ 'Found %(counter)d matching sale',
+ 'Found %(counter)d matching sales',
+ number=counter) % {'counter': counter}
+
class VoucherFilter(SortedFilterSet):
name = CharFilter(
@@ -93,3 +101,11 @@ class VoucherFilter(SortedFilterSet):
else:
q = Q(end_date__lte=value.stop)
return queryset.filter(q)
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard vouchers list',
+ 'Found %(counter)d matching voucher',
+ 'Found %(counter)d matching vouchers',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.py
index 33a3f25ed8..22a9cacc07 100644
--- a/saleor/dashboard/discount/views.py
+++ b/saleor/dashboard/discount/views.py
@@ -3,7 +3,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
from ...discount.models import Sale, Voucher
@@ -20,16 +20,9 @@ def sale_list(request):
sales = get_paginator_items(
sale_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = sale_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard sales list',
- 'Found %(counter)d matching sale',
- 'Found %(counter)d matching sales',
- number=counter) % {'counter': counter}
ctx = {
'sales': sales, 'filter': sale_filter,
- 'is_empty': not sale_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not sale_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/discount/sale/list.html', ctx)
@@ -73,16 +66,9 @@ def voucher_list(request):
vouchers = get_paginator_items(
voucher_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = voucher_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard vouchers list',
- 'Found %(counter)d matching voucher',
- 'Found %(counter)d matching vouchers',
- number=counter) % {'counter': counter}
ctx = {
'vouchers': vouchers, 'filter': voucher_filter,
- 'is_empty': not voucher_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not voucher_filter.queryset.exists()}
return TemplateResponse(
request, 'dashboard/discount/voucher/list.html', ctx)
diff --git a/saleor/dashboard/group/filters.py b/saleor/dashboard/group/filters.py
index 62b0d39172..ca3e63280c 100644
--- a/saleor/dashboard/group/filters.py
+++ b/saleor/dashboard/group/filters.py
@@ -1,5 +1,5 @@
from django.contrib.auth.models import Group
-from django.utils.translation import pgettext_lazy
+from django.utils.translation import npgettext, pgettext_lazy
from django_filters import (
CharFilter, ModelMultipleChoiceFilter, OrderingFilter)
@@ -26,3 +26,11 @@ class GroupFilter(SortedFilterSet):
class Meta:
model = Group
fields = []
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard groups list',
+ 'Found %(counter)d matching group',
+ 'Found %(counter)d matching groups',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/group/views.py b/saleor/dashboard/group/views.py
index acf274914d..fbe38be5da 100644
--- a/saleor/dashboard/group/views.py
+++ b/saleor/dashboard/group/views.py
@@ -4,7 +4,7 @@ from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import Group
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
from ..views import staff_member_required
@@ -22,16 +22,9 @@ def group_list(request):
for group in group_filter.qs]
groups = get_paginator_items(
groups, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))
- counter = group_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard groups list',
- 'Found %(counter)d matching group',
- 'Found %(counter)d matching groups',
- number=counter) % {'counter': counter}
ctx = {
'groups': groups, 'filter': group_filter,
- 'is_empty': not group_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not group_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/group/list.html', ctx)
diff --git a/saleor/dashboard/order/filters.py b/saleor/dashboard/order/filters.py
index c0f2af716d..363f0b012f 100644
--- a/saleor/dashboard/order/filters.py
+++ b/saleor/dashboard/order/filters.py
@@ -1,6 +1,6 @@
from django import forms
from django.db.models import Q
-from django.utils.translation import pgettext_lazy
+from django.utils.translation import npgettext, pgettext_lazy
from django_filters import (
CharFilter, ChoiceFilter, DateFromToRangeFilter, NumberFilter, RangeFilter,
OrderingFilter)
@@ -74,3 +74,11 @@ class OrderFilter(SortedFilterSet):
queryset.open() if value == OrderStatus.OPEN
else queryset.closed()
)
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard orders list',
+ 'Found %(counter)d matching order',
+ 'Found %(counter)d matching orders',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 0d080a914d..f03c9eb9f3 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -6,7 +6,7 @@ from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.template.context_processors import csrf
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from django_prices.templatetags.prices_i18n import gross
from payments import PaymentStatus
from prices import Price
@@ -37,16 +37,9 @@ def order_list(request):
orders = get_paginator_items(
order_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = order_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard orders list',
- 'Found %(counter)d matching order',
- 'Found %(counter)d matching orders',
- number=counter) % {'counter': counter}
ctx = {
'orders': orders, 'filter': order_filter,
- 'is_empty': not order_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not order_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/order/list.html', ctx)
diff --git a/saleor/dashboard/product/filters.py b/saleor/dashboard/product/filters.py
index 682d580d5b..7f674952b2 100644
--- a/saleor/dashboard/product/filters.py
+++ b/saleor/dashboard/product/filters.py
@@ -1,5 +1,5 @@
from django import forms
-from django.utils.translation import pgettext_lazy
+from django.utils.translation import npgettext, pgettext_lazy
from django_filters import (
CharFilter, ChoiceFilter, ModelMultipleChoiceFilter, RangeFilter,
OrderingFilter)
@@ -63,6 +63,14 @@ class ProductFilter(SortedFilterSet):
model = Product
fields = []
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard products list',
+ 'Found %(counter)d matching product',
+ 'Found %(counter)d matching products',
+ number=counter) % {'counter': counter}
+
class ProductAttributeFilter(SortedFilterSet):
name = CharFilter(
@@ -77,6 +85,15 @@ class ProductAttributeFilter(SortedFilterSet):
model = ProductAttribute
fields = []
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard '
+ 'product attributes list',
+ 'Found %(counter)d matching attribute',
+ 'Found %(counter)d matching attributes',
+ number=counter) % {'counter': counter}
+
class ProductClassFilter(SortedFilterSet):
name = CharFilter(
@@ -91,6 +108,14 @@ class ProductClassFilter(SortedFilterSet):
model = ProductClass
fields = ['name', 'product_attributes', 'variant_attributes']
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard product types list',
+ 'Found %(counter)d matching product type',
+ 'Found %(counter)d matching product types',
+ number=counter) % {'counter': counter}
+
class StockLocationFilter(SortedFilterSet):
sort_by = OrderingFilter(
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 6b5f857fcd..7f2b168ecb 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -5,7 +5,7 @@ from django.db.models import Q
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect, reverse
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, npgettext_lazy, pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from django.views.decorators.http import require_POST
from django_prices.templatetags.prices_i18n import gross
@@ -34,20 +34,13 @@ def product_class_list(request):
classes = get_paginator_items(
class_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = class_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard product types list',
- 'Found %(counter)d matching product type',
- 'Found %(counter)d matching product types',
- number=counter) % {'counter': counter}
classes.object_list = [
(pc.pk, pc.name, pc.has_variants, pc.product_attributes.all(),
pc.variant_attributes.all())
for pc in classes.object_list]
ctx = {
'form': form, 'product_classes': classes, 'filter': class_filter,
- 'is_empty': not class_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not class_filter.queryset.exists()}
return TemplateResponse(
request,
'dashboard/product/product_class/list.html',
@@ -124,18 +117,11 @@ def product_list(request):
products = get_paginator_items(
product_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = product_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard products list',
- 'Found %(counter)d matching product',
- 'Found %(counter)d matching products',
- number=counter) % {'counter': counter}
ctx = {
'bulk_action_form': forms.ProductBulkUpdate(),
'products': products, 'product_classes': product_classes,
- 'filter': product_filter, 'summary_msg': summary_msg,
- 'is_empty': not product_filter.queryset.exists()
- }
+ 'filter': product_filter,
+ 'is_empty': not product_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/product/list.html', ctx)
@@ -510,16 +496,9 @@ def attribute_list(request):
for attribute in attribute_filter.qs]
attributes = get_paginator_items(
attributes, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))
- counter = attribute_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard product attributes list',
- 'Found %(counter)d matching attribute',
- 'Found %(counter)d matching attributes',
- number=counter) % {'counter': counter}
ctx = {
'attributes': attributes, 'filter': attribute_filter,
- 'is_empty': not attribute_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not attribute_filter.queryset.exists()}
return TemplateResponse(
request, 'dashboard/product/product_attribute/list.html', ctx)
diff --git a/saleor/dashboard/shipping/filters.py b/saleor/dashboard/shipping/filters.py
index f7e22ad6fb..5e61d6f89f 100644
--- a/saleor/dashboard/shipping/filters.py
+++ b/saleor/dashboard/shipping/filters.py
@@ -1,4 +1,4 @@
-from django.utils.translation import pgettext_lazy
+from django.utils.translation import npgettext, pgettext_lazy
from django_filters import (
CharFilter, ChoiceFilter, OrderingFilter, RangeFilter)
@@ -30,3 +30,11 @@ class ShippingMethodFilter(SortedFilterSet):
class Meta:
model = ShippingMethod
fields = []
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard shipping methods list',
+ 'Found %(counter)d matching shipping method',
+ 'Found %(counter)d matching shipping methods',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/shipping/views.py b/saleor/dashboard/shipping/views.py
index d188c69494..d392e6cc73 100644
--- a/saleor/dashboard/shipping/views.py
+++ b/saleor/dashboard/shipping/views.py
@@ -3,7 +3,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
from ...shipping.models import ShippingMethod, ShippingMethodCountry
@@ -15,23 +15,16 @@ from .forms import ShippingMethodCountryForm, ShippingMethodForm
@staff_member_required
@permission_required('shipping.view_shipping')
def shipping_method_list(request):
- methods = (ShippingMethod.objects.prefetch_related('price_per_country')
- .order_by('name'))
+ methods = ShippingMethod.objects.prefetch_related(
+ 'price_per_country').order_by('name')
shipping_method_filter = ShippingMethodFilter(
request.GET, queryset=methods)
methods = get_paginator_items(
shipping_method_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = shipping_method_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard shipping methods list',
- 'Found %(counter)d matching shipping method',
- 'Found %(counter)d matching shipping methods',
- number=counter) % {'counter': counter}
ctx = {
'shipping_methods': methods, 'filter': shipping_method_filter,
- 'is_empty': not shipping_method_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not shipping_method_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/shipping/list.html', ctx)
diff --git a/saleor/dashboard/staff/filters.py b/saleor/dashboard/staff/filters.py
index 5ea35dc770..f7e736b792 100644
--- a/saleor/dashboard/staff/filters.py
+++ b/saleor/dashboard/staff/filters.py
@@ -1,10 +1,7 @@
-from django import forms
from django.contrib.auth.models import Group
-from django.utils.translation import pgettext_lazy
-from django_filters import (
- CharFilter, ChoiceFilter, ModelMultipleChoiceFilter, OrderingFilter)
+from django.utils.translation import pgettext_lazy, npgettext
+from django_filters import ModelMultipleChoiceFilter, OrderingFilter
-from ...core.filters import SortedFilterSet
from ...userprofile.models import User
from ..customer.filters import UserFilter
@@ -36,3 +33,11 @@ class StaffFilter(UserFilter):
class Meta:
model = User
fields = []
+
+ def get_summary_message(self):
+ counter = self.qs.count()
+ return npgettext(
+ 'Number of matching records in the dashboard staff members list',
+ 'Found %(counter)d matching staff member',
+ 'Found %(counter)d matching staff members',
+ number=counter) % {'counter': counter}
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
index 8ed0b18cef..575508a521 100644
--- a/saleor/dashboard/staff/views.py
+++ b/saleor/dashboard/staff/views.py
@@ -3,7 +3,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
-from django.utils.translation import npgettext, pgettext_lazy
+from django.utils.translation import pgettext_lazy
from .emails import send_set_password_email
from .filters import StaffFilter
@@ -16,23 +16,15 @@ from ...userprofile.models import User
@staff_member_required
@permission_required('userprofile.view_staff')
def staff_list(request):
- staff_members = (User.objects.filter(is_staff=True)
- .prefetch_related('default_billing_address')
- .order_by('email'))
+ staff_members = User.objects.filter(is_staff=True).prefetch_related(
+ 'default_billing_address').order_by('email')
staff_filter = StaffFilter(request.GET, queryset=staff_members)
staff_members = get_paginator_items(
staff_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
- counter = staff_filter.qs.count()
- summary_msg = npgettext(
- 'Number of matching records in the dashboard staff members list',
- 'Found %(counter)d matching staff member',
- 'Found %(counter)d matching staff members',
- number=counter) % {'counter': counter}
ctx = {
'staff': staff_members, 'filter': staff_filter,
- 'is_empty': not staff_filter.queryset.exists(),
- 'summary_msg': summary_msg}
+ 'is_empty': not staff_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/staff/list.html', ctx)