Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add collection filter
akjanikcd2bc41a86d1
diff --git a/saleor/dashboard/collection/filters.py b/saleor/dashboard/collection/filters.pynew file mode 100644index 0000000000..10ef5da693--- /dev/null+++ b/saleor/dashboard/collection/filters.py@@ -0,0 +1,30 @@+from django_filters import CharFilter, OrderingFilter+from django.utils.translation import npgettext, pgettext_lazy++from ...core.filters import SortedFilterSet+from ...product.models import Collection++SORT_BY_FIELDS = {+ 'name': pgettext_lazy('Category list sorting option', 'name')}+++class CollectionFilter(SortedFilterSet):+ name = CharFilter(+ label=pgettext_lazy('Collection list name filter label', 'Name'),+ lookup_expr='icontains')+ sort_by = OrderingFilter(+ label=pgettext_lazy('Collection list sorting filter label', 'Sort by'),+ fields=SORT_BY_FIELDS.keys(),+ field_labels=SORT_BY_FIELDS)++ class Meta:+ model = Collection+ fields = []++ def get_summary_message(self):+ counter = self.qs.count()+ return npgettext(+ 'Number of matching records in the dashboard collections list',+ 'Found %(counter)d matching collection',+ 'Found %(counter)d matching collections',+ number=counter) % {'counter': counter}diff --git a/saleor/dashboard/collection/views.py b/saleor/dashboard/collection/views.pyindex 9e85fec46a..1495bd2082 100644--- a/saleor/dashboard/collection/views.py+++ b/saleor/dashboard/collection/views.py@@ -1,4 +1,5 @@from django.template.response import TemplateResponse+from django.conf import settingsfrom django.contrib import messagesfrom django.contrib.auth.decorators import permission_requiredfrom django.core.urlresolvers import reverse@@ -9,6 +10,7 @@ from django.utils.translation import pgettext_lazyfrom ...product.models import Collectionfrom ...core.utils import get_paginator_itemsfrom ..views import staff_member_required+from .filters import CollectionFilterfrom .forms import CollectionForm@@ -16,8 +18,13 @@ from .forms import CollectionForm@permission_required('product.view_product')def collection_list(request):collections = Collection.objects.prefetch_related('products').all()- collections = get_paginator_items(collections, 30, request.GET.get('page'))- ctx = {'collections': collections}+ collection_filter = CollectionFilter(request.GET, queryset=collections)+ collections = get_paginator_items(+ collection_filter.qs, settings.DASHBOARD_PAGINATE_BY,+ request.GET.get('page'))+ ctx = {+ 'collections': collections,'filter_set': collection_filter,+ 'is_empty': not collection_filter.queryset.exists()}return TemplateResponse(request, 'dashboard/collection/list.html', ctx)diff --git a/templates/dashboard/collection/list.html b/templates/dashboard/collection/list.htmlindex bedcd2d94e..677e79b69f 100644--- a/templates/dashboard/collection/list.html+++ b/templates/dashboard/collection/list.html@@ -30,7 +30,7 @@{% block content %}<div class="row">- <div class="col s12">+ <div class="col s12 l9">{% if collections %}<div class="card"><div class="data-table-container">@@ -44,8 +44,8 @@{% sorting_header 'description' label is_wide=True %}</tr></thead>- <tbody>- {% for node in collections %}+ {% for node in collections %}+ <tbody><tr data-action-go="{% if perms.product.edit_product %}{% url 'dashboard:collection-update' node.pk %}{% endif %}"><td>{{ node.name }}@@ -54,15 +54,31 @@{% if node.products %}{% trans "Products in collection:" %} {{ node.products.count }}{% else %}- + -{% endif %}</td></tr>- {% endfor %}- </tbody>+ </tbody>+ {% endfor %}+ </table></div></div>+ {% else %}+ {% if is_empty %}+ {% include 'dashboard/category/zero_page.html' %}+ {% else %}+ <div class="col s12">+ <div class="not-found">+ <p class="grey-text">+ {% trans "No collections found." context "Empty category list message" %}+ </p>+ </div>+ </div>+ {% endif %}{% endif %}</div>+ <div class="col s12 l3" id="filters">+ {% if not is_empty %}{% filters filter_set %}{% endif %}+ </div></div>{% endblock %}diff --git a/templates/dashboard/collection/zero_page.html b/templates/dashboard/collection/zero_page.htmlnew file mode 100644index 0000000000..7bd0c85811--- /dev/null+++ b/templates/dashboard/collection/zero_page.html@@ -0,0 +1,12 @@+{% extends 'dashboard/base_zero_page.html' %}+{% load i18n %}+{% load static %}++{% block title %}{% trans "No collections found." %}{% endblock %}+{% block content %}+ {% static "dashboard/images/add.svg" as img_path %}+ {% blocktrans %}+ Collections are used to organize products into custom groups.<br>+ You can create collections by using the <span class="btn-fab-presentation"><svg data-src="{{ img_path }}" /></span> button.+ {% endblocktrans %}+{% endblock %}