Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Inherit getting filter set summary message
Anna Siwik029a4794e8bc
diff --git a/saleor/dashboard/category/filters.py b/saleor/dashboard/category/filters.pyindex 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_lazyfrom django_filters import CharFilter, OrderingFilterfrom ...core.filters import SortedFilterSet@@ -27,3 +27,11 @@ class CategoryFilter(SortedFilterSet):class Meta:model = Categoryfields = []++ 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.pyindex 825b6cd850..b9c1403d90 100644--- a/saleor/dashboard/category/views.py+++ b/saleor/dashboard/category/views.py@@ -5,7 +5,7 @@ from django.http import JsonResponsefrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom django.urls import reverse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...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.pyindex b3ed86b539..7ae3daced3 100644--- a/saleor/dashboard/customer/filters.py+++ b/saleor/dashboard/customer/filters.py@@ -1,8 +1,7 @@from django import formsfrom 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, OrderingFilterfrom django_countries import countriesfrom ...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.pyindex 99c42ea166..17f967a326 100644--- a/saleor/dashboard/customer/views.py+++ b/saleor/dashboard/customer/views.py@@ -1,10 +1,9 @@from django.conf import settingsfrom django.contrib import messagesfrom django.contrib.auth.decorators import permission_required-from django.db.models import Count, Maxfrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...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.pyindex fc7d3d667c..6f3cd11704 100644--- a/saleor/dashboard/discount/filters.py+++ b/saleor/dashboard/discount/filters.py@@ -1,6 +1,6 @@from django import formsfrom django.db.models import Q-from django.utils.translation import pgettext_lazy+from django.utils.translation import pgettext_lazy, npgettextfrom django_filters import (CharFilter, ChoiceFilter, DateFromToRangeFilter, ModelMultipleChoiceFilter,OrderingFilter, RangeFilter)@@ -53,6 +53,14 @@ class SaleFilter(SortedFilterSet):model = Salefields = []+ 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.pyindex 33a3f25ed8..22a9cacc07 100644--- a/saleor/dashboard/discount/views.py+++ b/saleor/dashboard/discount/views.py@@ -3,7 +3,7 @@ from django.contrib import messagesfrom django.contrib.auth.decorators import permission_requiredfrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...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.pyindex 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_lazyfrom django_filters import (CharFilter, ModelMultipleChoiceFilter, OrderingFilter)@@ -26,3 +26,11 @@ class GroupFilter(SortedFilterSet):class Meta:model = Groupfields = []++ 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.pyindex 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_requiredfrom django.contrib.auth.models import Groupfrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ..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.pyindex c0f2af716d..363f0b012f 100644--- a/saleor/dashboard/order/filters.py+++ b/saleor/dashboard/order/filters.py@@ -1,6 +1,6 @@from django import formsfrom django.db.models import Q-from django.utils.translation import pgettext_lazy+from django.utils.translation import npgettext, pgettext_lazyfrom django_filters import (CharFilter, ChoiceFilter, DateFromToRangeFilter, NumberFilter, RangeFilter,OrderingFilter)@@ -74,3 +74,11 @@ class OrderFilter(SortedFilterSet):queryset.open() if value == OrderStatus.OPENelse 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.pyindex 0d080a914d..f03c9eb9f3 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -6,7 +6,7 @@ from django.http import HttpResponsefrom django.shortcuts import get_object_or_404, redirectfrom django.template.context_processors import csrffrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom django_prices.templatetags.prices_i18n import grossfrom payments import PaymentStatusfrom 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.pyindex 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_lazyfrom django_filters import (CharFilter, ChoiceFilter, ModelMultipleChoiceFilter, RangeFilter,OrderingFilter)@@ -63,6 +63,14 @@ class ProductFilter(SortedFilterSet):model = Productfields = []+ 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 = ProductAttributefields = []+ 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 = ProductClassfields = ['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.pyindex 6b5f857fcd..7f2b168ecb 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -5,7 +5,7 @@ from django.db.models import Qfrom django.http import JsonResponsefrom django.shortcuts import get_object_or_404, redirect, reversefrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, npgettext_lazy, pgettext_lazy+from django.utils.translation import npgettext_lazy, pgettext_lazyfrom django.views.decorators.http import require_POSTfrom 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.pyindex 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_lazyfrom django_filters import (CharFilter, ChoiceFilter, OrderingFilter, RangeFilter)@@ -30,3 +30,11 @@ class ShippingMethodFilter(SortedFilterSet):class Meta:model = ShippingMethodfields = []++ 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.pyindex d188c69494..d392e6cc73 100644--- a/saleor/dashboard/shipping/views.py+++ b/saleor/dashboard/shipping/views.py@@ -3,7 +3,7 @@ from django.contrib import messagesfrom django.contrib.auth.decorators import permission_requiredfrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...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.pyindex 5ea35dc770..f7e736b792 100644--- a/saleor/dashboard/staff/filters.py+++ b/saleor/dashboard/staff/filters.py@@ -1,10 +1,7 @@-from django import formsfrom 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 SortedFilterSetfrom ...userprofile.models import Userfrom ..customer.filters import UserFilter@@ -36,3 +33,11 @@ class StaffFilter(UserFilter):class Meta:model = Userfields = []++ 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.pyindex 8ed0b18cef..575508a521 100644--- a/saleor/dashboard/staff/views.py+++ b/saleor/dashboard/staff/views.py@@ -3,7 +3,7 @@ from django.contrib import messagesfrom django.contrib.auth.decorators import permission_requiredfrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from django.utils.translation import npgettext, pgettext_lazy+from django.utils.translation import pgettext_lazyfrom .emails import send_set_password_emailfrom .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)