Skip to content

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

Add results summary to templates with SortedFilterSet

Anna Siwika3060f454de4
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index b9c1403d90..2e962ffe02 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 pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from ...core.utils import get_paginator_items
from ...product.models import Category
@@ -22,9 +22,15 @@ def category_list(request):
categories = get_paginator_items(
category_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching category',
+ 'Found %(counter)d matching categories',
+ 'counter') % {'counter': category_filter.qs.count() }
ctx = {
'categories': categories, 'filter': category_filter,
- 'is_empty': not category_filter.queryset.exists()}
+ 'is_empty': not category_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(request, 'dashboard/category/list.html', ctx)
@@ -89,8 +95,13 @@ def category_detail(request, pk):
categories = get_paginator_items(
category_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching subcategory',
+ 'Found %(counter)d matching subcategories',
+ 'counter') % {'counter': category_filter.qs.count() }
ctx = {'categories': categories, 'path': path, 'root': root,
- 'filter': category_filter,
+ 'filter': category_filter, 'summary_msg': summary_msg,
'is_empty': not category_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index 233c9748ff..7a2e1d2628 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -4,7 +4,7 @@ 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 pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from ...core.utils import get_paginator_items
from ...userprofile.models import User
@@ -24,9 +24,15 @@ def customer_list(request):
customers = get_paginator_items(
customer_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching customer',
+ 'Found %(counter)d matching customers',
+ 'counter') % {'counter': customer_filter.qs.count() }
ctx = {
'customers': customers, 'filter': customer_filter,
- 'is_empty': not customer_filter.queryset.exists()}
+ 'is_empty': not customer_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(request, 'dashboard/customer/list.html', ctx)
diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.py
index 22a9cacc07..aa6aa535c9 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 pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from ...core.utils import get_paginator_items
from ...discount.models import Sale, Voucher
@@ -20,9 +20,15 @@ def sale_list(request):
sales = get_paginator_items(
sale_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching sale',
+ 'Found %(counter)d matching sales',
+ 'counter') % {'counter': sale_filter.qs.count() }
ctx = {
'sales': sales, 'filter': sale_filter,
- 'is_empty': not sale_filter.queryset.exists()}
+ 'is_empty': not sale_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(request, 'dashboard/discount/sale/list.html', ctx)
@@ -66,9 +72,15 @@ def voucher_list(request):
vouchers = get_paginator_items(
voucher_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching voucher',
+ 'Found %(counter)d matching vouchers',
+ 'counter') % {'counter': voucher_filter.qs.count() }
ctx = {
'vouchers': vouchers, 'filter': voucher_filter,
- 'is_empty': not voucher_filter.queryset.exists()}
+ 'is_empty': not voucher_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(
request, 'dashboard/discount/voucher/list.html', ctx)
diff --git a/saleor/dashboard/group/views.py b/saleor/dashboard/group/views.py
index 4ac54107dc..e4c866194f 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 pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from ...core.utils import get_paginator_items
from ..views import staff_member_required
@@ -22,9 +22,15 @@ def group_list(request):
for group in group_filter.qs]
groups = get_paginator_items(
groups, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching group',
+ 'Found %(counter)d matching groups',
+ 'counter') % {'counter': group_filter.qs.count() }
ctx = {
'groups': groups, 'filter': group_filter,
- 'is_empty': not group_filter.queryset.exists()}
+ 'is_empty': not group_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(request, 'dashboard/group/list.html', ctx)
@@ -35,10 +41,8 @@ def group_create(request):
form = GroupPermissionsForm(request.POST or None)
if form.is_valid():
form.save()
- messages.success(
- request,
- pgettext_lazy('Dashboard message',
- 'Created group'))
+ msg = pgettext_lazy('Dashboard message', 'Created group')
+ messages.success(request, msg)
return redirect('dashboard:group-list')
ctx = {'group': group, 'form': form}
return TemplateResponse(request, 'dashboard/group/detail.html', ctx)
@@ -51,10 +55,9 @@ def group_details(request, pk):
form = GroupPermissionsForm(request.POST or None, instance=group)
if form.is_valid():
form.save()
- messages.success(
- request,
- pgettext_lazy('Dashboard message', 'Updated group %s') % group.name
- )
+ msg = pgettext_lazy(
+ 'Dashboard message', 'Updated group %s') % group.name
+ messages.success(request, msg)
return redirect('dashboard:group-list')
ctx = {'group': group, 'form': form}
return TemplateResponse(request, 'dashboard/group/detail.html', ctx)
@@ -66,10 +69,8 @@ def group_delete(request, pk):
group = get_object_or_404(Group, pk=pk)
if request.method == 'POST':
group.delete()
- messages.success(
- request,
- pgettext_lazy('Dashboard message', 'Removed group %s') % group
- )
+ msg = pgettext_lazy('Dashboard message', 'Removed group %s') % group
+ messages.success(request, msg)
return redirect('dashboard:group-list')
return TemplateResponse(
request, 'dashboard/group/modal/confirm_delete.html', {'group': group})
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 1a36a1417d..6494dc5204 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -19,8 +19,8 @@ from .forms import (
MoveLinesForm, OrderNoteForm, RefundPaymentForm, ReleasePaymentForm,
RemoveVoucherForm, ShipGroupForm)
-from .utils import (create_packing_slip_pdf, create_invoice_pdf,
- get_statics_absolute_url)
+from .utils import (
+ create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url)
from ..views import staff_member_required
from ...core.utils import get_paginator_items
from ...order import GroupStatus
@@ -34,14 +34,14 @@ def order_list(request):
orders = (Order.objects.prefetch_related(
'payments', 'groups__lines', 'user').order_by('-pk'))
order_filter = OrderFilter(request.GET, queryset=orders)
+ orders = get_paginator_items(
+ order_filter.qs, settings.DASHBOARD_PAGINATE_BY,
+ request.GET.get('page'))
summary_msg = npgettext_lazy(
'Filter set results summary',
'Found %(counter)d matching product',
'Found %(counter)d matching products',
'counter') % {'counter': order_filter.qs.count() }
- orders = get_paginator_items(
- order_filter.qs, settings.DASHBOARD_PAGINATE_BY,
- request.GET.get('page'))
ctx = {
'orders': orders, 'filter': order_filter,
'is_empty': not order_filter.queryset.exists(),
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 70aa11affe..4d9d3248f8 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -34,13 +34,19 @@ def product_class_list(request):
classes = get_paginator_items(
class_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching product type',
+ 'Found %(counter)d matching product types',
+ 'counter') % {'counter': class_filter.qs.count() }
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()}
+ 'is_empty': not class_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(
request,
'dashboard/product/product_class/list.html',
@@ -117,10 +123,15 @@ def product_list(request):
products = get_paginator_items(
product_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching product',
+ 'Found %(counter)d matching products',
+ 'counter') % {'counter': product_filter.qs.count() }
ctx = {
'bulk_action_form': forms.ProductBulkUpdate(),
'products': products, 'product_classes': product_classes,
- 'filter': product_filter,
+ 'filter': product_filter, 'summary_msg': summary_msg,
'is_empty': not product_filter.queryset.exists()
}
return TemplateResponse(request, 'dashboard/product/list.html', ctx)
@@ -497,13 +508,17 @@ def attribute_list(request):
for attribute in attribute_filter.qs]
attributes = get_paginator_items(
attributes, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching attribute',
+ 'Found %(counter)d matching attributes',
+ 'counter') % {'counter': attribute_filter.qs.count() }
ctx = {
'attributes': attributes, 'filter': attribute_filter,
- 'is_empty': not attribute_filter.queryset.exists()}
+ 'is_empty': not attribute_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(
- request,
- 'dashboard/product/product_attribute/list.html',
- ctx)
+ request, 'dashboard/product/product_attribute/list.html', ctx)
@staff_member_required
diff --git a/saleor/dashboard/shipping/views.py b/saleor/dashboard/shipping/views.py
index a8b006629a..634ff84cbd 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 pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from ...core.utils import get_paginator_items
from ...shipping.models import ShippingMethod, ShippingMethodCountry
@@ -22,9 +22,15 @@ def shipping_method_list(request):
methods = get_paginator_items(
shipping_method_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching shipping method',
+ 'Found %(counter)d matching shipping methods',
+ 'counter') % {'counter': shipping_method_filter.qs.count() }
ctx = {
'shipping_methods': methods, 'filter': shipping_method_filter,
- 'is_empty': not shipping_method_filter.queryset.exists()}
+ 'is_empty': not shipping_method_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(request, 'dashboard/shipping/list.html', ctx)
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
index f04720b5f4..6d8c28139a 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 pgettext_lazy
+from django.utils.translation import npgettext_lazy, pgettext_lazy
from .emails import send_set_password_email
from .filters import StaffFilter
@@ -23,9 +23,15 @@ def staff_list(request):
staff_members = get_paginator_items(
staff_filter.qs, settings.DASHBOARD_PAGINATE_BY,
request.GET.get('page'))
+ summary_msg = npgettext_lazy(
+ 'Filter set results summary',
+ 'Found %(counter)d matching staff member',
+ 'Found %(counter)d matching staff members',
+ 'counter') % {'counter': staff_filter.qs.count() }
ctx = {
'staff': staff_members, 'filter': staff_filter,
- 'is_empty': not staff_filter.queryset.exists()}
+ 'is_empty': not staff_filter.queryset.exists(),
+ 'summary_msg': summary_msg}
return TemplateResponse(request, 'dashboard/staff/list.html', ctx)
diff --git a/templates/dashboard/category/detail.html b/templates/dashboard/category/detail.html
index 347ffb4576..58eaca544e 100644
--- a/templates/dashboard/category/detail.html
+++ b/templates/dashboard/category/detail.html
@@ -188,7 +188,7 @@
{% paginate categories %}
</div>
<div class="col s12 l3" id="filters">
- {% add_filters filter %}
+ {% add_filters filter summary_msg %}
</div>
</div>
{% endif %}
diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.html
index 9ca87fe27e..a06b00e713 100644
--- a/templates/dashboard/category/list.html
+++ b/templates/dashboard/category/list.html
@@ -102,7 +102,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/customer/list.html b/templates/dashboard/customer/list.html
index 816e288647..1aeb59f7ee 100644
--- a/templates/dashboard/customer/list.html
+++ b/templates/dashboard/customer/list.html
@@ -97,7 +97,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/discount/sale/list.html b/templates/dashboard/discount/sale/list.html
index be964cec82..776871f28a 100644
--- a/templates/dashboard/discount/sale/list.html
+++ b/templates/dashboard/discount/sale/list.html
@@ -90,7 +90,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.html
index 20bb8b5e8e..1fe9c1575b 100644
--- a/templates/dashboard/discount/voucher/list.html
+++ b/templates/dashboard/discount/voucher/list.html
@@ -145,7 +145,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/group/list.html b/templates/dashboard/group/list.html
index 58ba11892a..505e389726 100644
--- a/templates/dashboard/group/list.html
+++ b/templates/dashboard/group/list.html
@@ -88,7 +88,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.html
index fb9ad5903f..484e5bca47 100644
--- a/templates/dashboard/product/list.html
+++ b/templates/dashboard/product/list.html
@@ -131,7 +131,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/product/product_attribute/list.html b/templates/dashboard/product/product_attribute/list.html
index 3eb6a921b2..a735f360fd 100644
--- a/templates/dashboard/product/product_attribute/list.html
+++ b/templates/dashboard/product/product_attribute/list.html
@@ -85,7 +85,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/product/product_class/list.html b/templates/dashboard/product/product_class/list.html
index c4bb3b0c63..fb368a9faf 100644
--- a/templates/dashboard/product/product_class/list.html
+++ b/templates/dashboard/product/product_class/list.html
@@ -100,7 +100,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
<div id="modal-product-class" class="modal">
diff --git a/templates/dashboard/shipping/list.html b/templates/dashboard/shipping/list.html
index f1534e3b41..c215c239dd 100644
--- a/templates/dashboard/shipping/list.html
+++ b/templates/dashboard/shipping/list.html
@@ -98,7 +98,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}
diff --git a/templates/dashboard/staff/list.html b/templates/dashboard/staff/list.html
index 376b5c1ed7..c3e784d6d8 100644
--- a/templates/dashboard/staff/list.html
+++ b/templates/dashboard/staff/list.html
@@ -110,7 +110,7 @@
{% endif %}
</div>
<div class="col s12 l3" id="filters">
- {% if not is_empty %}{% add_filters filter %}{% endif %}
+ {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}
</div>
</div>
{% endblock %}