Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Get summary message from filter set
Anna Siwikfb2c52348155
diff --git a/saleor/core/filters.py b/saleor/core/filters.pyindex 5234257b05..a519de43bc 100644--- a/saleor/core/filters.py+++ b/saleor/core/filters.py@@ -1,15 +1,26 @@+from django.utils.translation import npgettextfrom django_filters import FilterSetclass SortedFilterSet(FilterSet):- '''- Base class for filtersets used in dashboard views. Adds flag- is_bound_unsorted to indicate if FilterSet has data from filters other- than sort_by or page.- '''+ """+ Base class for filter sets used in dashboard views. Adds flag+ is_bound_unsorted to indicate if FilterSet has data from filters+ other than sort_by or page.+ """def __init__(self, data, *args, **kwargs):self.is_bound_unsorted = self.set_is_bound_unsorted(data)super(SortedFilterSet, self).__init__(data, *args, **kwargs)def set_is_bound_unsorted(self, data):return any([key not in {'sort_by', 'page'} for key in data.keys()])++ def get_summary_message(self):+ """Returns message displayed in dashboard filter cards.+ Inherited by subclasses for record specific naming."""+ counter = self.qs.count()+ return npgettext(+ 'Number of matching records in the dashboard list',+ 'Found %(counter)d matching record',+ 'Found %(counter)d matching records',+ number=counter) % {'counter': counter}diff --git a/saleor/dashboard/templatetags/utils.py b/saleor/dashboard/templatetags/utils.pyindex 94f5e83dfa..898892ed76 100644--- a/saleor/dashboard/templatetags/utils.py+++ b/saleor/dashboard/templatetags/utils.py@@ -76,8 +76,7 @@ def margins_for_variant(variant):@register.inclusion_tag('dashboard/includes/_filters.html', takes_context=True)-def add_filters(- context, filter_set, summary_msg, sort_by_filter_name='sort_by'):+def add_filters(context, filter_set, sort_by_filter_name='sort_by'):"""Rendering filters template based on FilterSet."""chips = []request_get = context['request'].GET.copy()@@ -104,7 +103,7 @@ def add_filters(items = handle_default(field, request_get)chips.extend(items)return {- 'chips': chips, 'filter': filter_set, 'summary_msg': summary_msg,+ 'chips': chips, 'filter': filter_set,'sort_by': request_get.get(sort_by_filter_name, None)}diff --git a/templates/dashboard/category/detail.html b/templates/dashboard/category/detail.htmlindex 58eaca544e..347ffb4576 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 summary_msg %}+ {% add_filters filter %}</div></div>{% endif %}diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.htmlindex a06b00e713..9ca87fe27e 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/customer/list.html b/templates/dashboard/customer/list.htmlindex 1aeb59f7ee..816e288647 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/discount/sale/list.html b/templates/dashboard/discount/sale/list.htmlindex 776871f28a..be964cec82 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.htmlindex 1fe9c1575b..20bb8b5e8e 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/group/list.html b/templates/dashboard/group/list.htmlindex 505e389726..58ba11892a 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/includes/_filters.html b/templates/dashboard/includes/_filters.htmlindex b0479d963c..7a455de7c5 100644--- a/templates/dashboard/includes/_filters.html+++ b/templates/dashboard/includes/_filters.html@@ -8,7 +8,7 @@<div class="card-content"><div class="col s12"><span class="card-title">{% trans 'Filters' context 'Dashboard card title' %}</span>- {{ summary_msg }}+ {{ filter.get_summary_message }}<span class="collapse-activate hide-on-large-only"><svg data-src="{% static '/images/filter_icon.svg' %}" /></span></div><div class="col s12 hide-on-large-only chips-container">diff --git a/templates/dashboard/order/list.html b/templates/dashboard/order/list.htmlindex 71f052a7a7..40cbef0f1a 100644--- a/templates/dashboard/order/list.html+++ b/templates/dashboard/order/list.html@@ -41,7 +41,7 @@{% endif %}</div><div class="col s12 l3" id="filters">- {% if not is_empty %}{% add_filters filter summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.htmlindex 484e5bca47..fb9ad5903f 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/product/product_attribute/list.html b/templates/dashboard/product/product_attribute/list.htmlindex a735f360fd..3eb6a921b2 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/product/product_class/list.html b/templates/dashboard/product/product_class/list.htmlindex fb368a9faf..c4bb3b0c63 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div><div id="modal-product-class" class="modal">diff --git a/templates/dashboard/shipping/list.html b/templates/dashboard/shipping/list.htmlindex c215c239dd..f1534e3b41 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}diff --git a/templates/dashboard/staff/list.html b/templates/dashboard/staff/list.htmlindex c3e784d6d8..376b5c1ed7 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 summary_msg %}{% endif %}+ {% if not is_empty %}{% add_filters filter %}{% endif %}</div></div>{% endblock %}