Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add sort_by name in category_list
michaldf7c0880893e
diff --git a/saleor/dashboard/category/filters.py b/saleor/dashboard/category/filters.pynew file mode 100644index 0000000000..90c0f3535a--- /dev/null+++ b/saleor/dashboard/category/filters.py@@ -0,0 +1,18 @@+from django_filters import (FilterSet, OrderingFilter)+from django.utils.translation import pgettext_lazy++from ...product.models import Category+++SORT_BY_FIELDS = {'name': pgettext_lazy('Product list sorting option', 'name')}+++class CategoryFilter(FilterSet):+ sort_by = OrderingFilter(+ label=pgettext_lazy('Product list sorting filter label', 'Sort by'),+ fields=SORT_BY_FIELDS.keys(),+ field_labels=SORT_BY_FIELDS)++ class Meta:+ model = Category+ fields = []diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.pyindex d816068320..7828c6714c 100644--- a/saleor/dashboard/category/views.py+++ b/saleor/dashboard/category/views.py@@ -12,6 +12,7 @@ from django.utils.translation import pgettext_lazyfrom ...core.utils import get_paginator_itemsfrom ...product.models import Categoryfrom ..views import staff_member_required+from .filters import CategoryFilterfrom .forms import CategoryForm@@ -25,9 +26,12 @@ def category_list(request, root_pk=None):root = get_object_or_404(Category, pk=root_pk)path = root.get_ancestors(include_self=True) if root else []categories = root.get_children()+ category_filter = CategoryFilter(request.GET, queryset=categories)categories = get_paginator_items(- categories, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))- ctx = {'categories': categories, 'path': path, 'root': root}+ category_filter.qs, settings.DASHBOARD_PAGINATE_BY,+ request.GET.get('page'))+ ctx = {'categories': categories, 'path': path, 'root': root,+ 'filter': category_filter}return TemplateResponse(request, 'dashboard/category/list.html', ctx)diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.htmlindex c2022d6d64..86a2ad29a9 100644--- a/templates/dashboard/category/list.html+++ b/templates/dashboard/category/list.html@@ -2,6 +2,7 @@{% load i18n %}{% load mptt_tags %}{% load materializecss %}+{% load get_sort_by_url_toggle from shop %}{% load staticfiles %}{% load utils %}@@ -115,8 +116,14 @@<table class="bordered highlight responsive data-table data-table-description no-align"><thead><tr>- <th>{% trans "Name" context "Category list table header name" %}</th>- <th>{% trans "Description" context "Category list table header description" %}</th>+ <th>+ <a href="{% get_sort_by_url_toggle 'name' %}">+ {% trans "Name" context "Category list table header name" %}+ </a>+ </th>+ <th>+ {% trans "Description" context "Category list table header description" %}+ </th></tr></thead><tbody>