Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update filters from Catalogue
michal051f7ea07965
diff --git a/saleor/dashboard/category/filters.py b/saleor/dashboard/category/filters.pyindex 6d621f6dff..0dc5866ea1 100644--- a/saleor/dashboard/category/filters.py+++ b/saleor/dashboard/category/filters.py@@ -6,7 +6,10 @@ from django.utils.translation import pgettext_lazyfrom ...product.models import Category-SORT_BY_FIELDS = {'name': pgettext_lazy('Product list sorting option', 'name')}+SORT_BY_FIELDS = {+ 'name': pgettext_lazy('Category list sorting option', 'name'),+ 'description': pgettext_lazy(+ 'Category list sorting option', 'description')}class CategoryFilter(FilterSet):diff --git a/saleor/dashboard/product/filters.py b/saleor/dashboard/product/filters.pyindex 8db78f4a25..25a98ab829 100644--- a/saleor/dashboard/product/filters.py+++ b/saleor/dashboard/product/filters.py@@ -3,10 +3,10 @@ from __future__ import unicode_literalsfrom django import formsfrom django.utils.translation import pgettext_lazyfrom django_filters import (- CharFilter, ChoiceFilter, FilterSet, RangeFilter, OrderingFilter)-from django_prices.models import PriceField+ CharFilter, ChoiceFilter, FilterSet, ModelMultipleChoiceFilter,+ RangeFilter, OrderingFilter)-from ...product.models import Product, ProductClass+from ...product.models import Category, Product, ProductClass, StockLocationPRODUCT_SORT_BY_FIELDS = {'name': pgettext_lazy('Product list sorting option', 'name'),@@ -15,6 +15,9 @@ PRODUCT_SORT_BY_FIELDS = {PRODUCT_CLASS_SORT_BY_FIELDS = {'name': pgettext_lazy('Product type list sorting option', 'name')}+STOCK_LOCATION_SORT_BY_FIELDS = {+ 'name': pgettext_lazy('Stock location list sorting option', 'name')}+PUBLISHED_CHOICES = (('1', pgettext_lazy('Is publish filter choice', 'Published')),('0', pgettext_lazy('Is publish filter choice', 'Not published')))@@ -26,15 +29,16 @@ FEATURED_CHOICES = (class ProductFilter(FilterSet):name = CharFilter(- label=pgettext_lazy('Product list name filter label', 'Name'),+ label=pgettext_lazy('Product list filter label', 'Name'),lookup_expr='icontains')- sort_by = OrderingFilter(- label=pgettext_lazy('Product list sorting filter label', 'Sort by'),- fields=PRODUCT_SORT_BY_FIELDS.keys(),- field_labels=PRODUCT_SORT_BY_FIELDS)+ categories = ModelMultipleChoiceFilter(+ label=pgettext_lazy('Product list filter label', 'Categories'),+ name='categories',+ queryset=Category.objects.all())+ price = RangeFilter(+ label=pgettext_lazy('Product list filter label', 'Price'))is_published = ChoiceFilter(- label=pgettext_lazy(- 'Product list is published filter label', 'Is published'),+ label=pgettext_lazy('Product list filter label', 'Is published'),choices=PUBLISHED_CHOICES,empty_label=pgettext_lazy('Filter empty choice label', 'All'),widget=forms.Select)@@ -44,15 +48,14 @@ class ProductFilter(FilterSet):choices=FEATURED_CHOICES,empty_label=pgettext_lazy('Filter empty choice label', 'All'),widget=forms.Select)+ sort_by = OrderingFilter(+ label=pgettext_lazy('Product list sorting filter label', 'Sort by'),+ fields=PRODUCT_SORT_BY_FIELDS.keys(),+ field_labels=PRODUCT_SORT_BY_FIELDS)class Meta:model = Product- fields = ['name', 'categories', 'is_published', 'is_featured', 'price']- filter_overrides = {- PriceField: {- 'filter_class': RangeFilter- }- }+ fields = []class ProductClassFilter(FilterSet):@@ -67,3 +70,15 @@ class ProductClassFilter(FilterSet):class Meta:model = ProductClassfields = ['name', 'product_attributes', 'variant_attributes']+++class StockLocationFilter(FilterSet):+ sort_by = OrderingFilter(+ label=pgettext_lazy(+ 'Stock location list sorting filter label', 'Sort by'),+ fields=STOCK_LOCATION_SORT_BY_FIELDS.keys(),+ field_labels=STOCK_LOCATION_SORT_BY_FIELDS)++ class Meta:+ model = StockLocation+ fields = []diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 1064a03593..c97c8b3a4a 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -18,7 +18,7 @@ from ...product.models import (from ...product.utils import (get_availability, get_product_costs_data, get_variant_costs_data)from ..views import staff_member_required-from .filters import ProductFilter, ProductClassFilter+from .filters import ProductFilter, ProductClassFilter, StockLocationFilterfrom . import forms@@ -119,7 +119,8 @@ def product_list(request):'dashboard:product-add', class_pk=form.cleaned_data['product_cls'])product_filter = ProductFilter(request.GET, queryset=products)products = get_paginator_items(- product_filter.qs, DASHBOARD_PAGINATE_BY, request.GET.get('page'))+ product_filter.qs, settings.DASHBOARD_PAGINATE_BY,+ request.GET.get('page'))sort_by = request.GET.get('sort_by')ctx = {@@ -583,11 +584,12 @@ def attribute_choice_value_delete(request, attribute_pk, value_pk):@permission_required('product.view_stock_location')def stock_location_list(request):stock_locations = StockLocation.objects.all().order_by('name')+ stock_location_filter = StockLocationFilter(+ request.GET, queryset=stock_locations)stock_locations = get_paginator_items(- stock_locations,- settings.DASHBOARD_PAGINATE_BY,+ stock_location_filter.qs, settings.DASHBOARD_PAGINATE_BY,request.GET.get('page'))- ctx = {'locations': stock_locations}+ ctx = {'locations': stock_locations, 'filter': stock_location_filter}return TemplateResponse(request,'dashboard/product/stock_location/list.html',diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.htmlindex 86a2ad29a9..a8bbe33142 100644--- a/templates/dashboard/category/list.html+++ b/templates/dashboard/category/list.html@@ -122,7 +122,9 @@</a></th><th>- {% trans "Description" context "Category list table header description" %}+ <a href="{% get_sort_by_url_toggle 'name' %}">+ {% trans "Description" context "Category list table header description" %}+ </a></th></tr></thead>diff --git a/templates/dashboard/product/stock_location/list.html b/templates/dashboard/product/stock_location/list.htmlindex 52f306c97a..eb1074616e 100644--- a/templates/dashboard/product/stock_location/list.html+++ b/templates/dashboard/product/stock_location/list.html@@ -1,6 +1,7 @@{% extends 'dashboard/base.html' %}{% load i18n %}{% load materializecss %}+{% load get_sort_by_url_toggle from shop %}{% load staticfiles %}{% load utils %}@@ -39,7 +40,11 @@<table class="highlight bordered data-table no-align"><thead><tr>- <th>{% trans "Name" context "Dashboard stock location table header name" %}</th>+ <th>+ <a href="{% get_sort_by_url_toggle 'name' %}">+ {% trans "Name" context "Dashboard stock location table header name" %}+ </a>+ </th></tr></thead><tbody>