Skip to content

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

Add filters for staff members

michaldd9d6cdbefe1
diff --git a/saleor/dashboard/customer/filters.py b/saleor/dashboard/customer/filters.py
index f88b08c953..4a6379fc65 100644
--- a/saleor/dashboard/customer/filters.py
+++ b/saleor/dashboard/customer/filters.py
@@ -16,8 +16,7 @@ SORT_BY_FIELDS = {
'num_orders': pgettext_lazy(
'Customer list sorting option', 'number of orders'),
'last_order': pgettext_lazy(
- 'Customer list sorting option', 'last order'),
-}
+ 'Customer list sorting option', 'last order')}
class CustomerFilter(FilterSet):
diff --git a/saleor/dashboard/staff/filters.py b/saleor/dashboard/staff/filters.py
new file mode 100644
index 0000000000..22dd197d43
--- /dev/null
+++ b/saleor/dashboard/staff/filters.py
@@ -0,0 +1,33 @@
+from __future__ import unicode_literals
+
+from django_filters import (FilterSet, RangeFilter, OrderingFilter)
+from django.utils.translation import pgettext_lazy
+from django_prices.models import PriceField
+
+from ...userprofile.models import User
+
+
+SORT_BY_FIELDS = {
+ 'email': pgettext_lazy(
+ 'Customer list sorting option', 'email'),
+ 'default_billing_address__first_name': pgettext_lazy(
+ 'Customer list sorting option', 'name'),
+ 'default_billing_address__city': pgettext_lazy(
+ 'Customer list sorting option', 'location')}
+
+
+class StaffFilter(FilterSet):
+ sort_by = OrderingFilter(
+ label=pgettext_lazy('Sale list sorting form', 'Sort by'),
+ fields=SORT_BY_FIELDS.keys(),
+ field_labels=SORT_BY_FIELDS
+ )
+
+ class Meta:
+ model = User
+ fields = ['email', 'is_active', 'groups']
+ filter_overrides = {
+ PriceField: {
+ 'filter_class': RangeFilter
+ }
+ }
diff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.py
index 6ad310b141..25c1ef8863 100644
--- a/saleor/dashboard/staff/views.py
+++ b/saleor/dashboard/staff/views.py
@@ -8,6 +8,7 @@ from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy
from .emails import send_set_password_email
+from .filters import StaffFilter
from .forms import StaffForm
from ..views import staff_member_required
from ...core.utils import get_paginator_items
@@ -20,9 +21,11 @@ def staff_list(request):
staff_members = (User.objects.filter(is_staff=True)
.prefetch_related('default_billing_address')
.order_by('email'))
+ staff_filter = StaffFilter(request.GET, queryset=staff_members)
staff_members = get_paginator_items(
- staff_members, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))
- ctx = {'staff': staff_members}
+ staff_filter.qs, settings.DASHBOARD_PAGINATE_BY,
+ request.GET.get('page'))
+ ctx = {'staff': staff_members, 'filter': staff_filter}
return TemplateResponse(request, 'dashboard/staff/list.html', ctx)
diff --git a/templates/dashboard/order/list.html b/templates/dashboard/order/list.html
index 5522bd08c0..6e0e5d862b 100644
--- a/templates/dashboard/order/list.html
+++ b/templates/dashboard/order/list.html
@@ -17,8 +17,8 @@
{% endblock %}
{% block content %}
+ {% include "dashboard/includes/_filters.html" %}
{% if orders %}
- {% include "dashboard/includes/_filters.html" %}
{% if orders %}
<div class="card">
{% include "dashboard/includes/_orders_table.html" with orders=orders %}
diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.html
index 3367f0c7b9..1020378a4e 100644
--- a/templates/dashboard/product/list.html
+++ b/templates/dashboard/product/list.html
@@ -44,8 +44,8 @@
{% block menu_catalogue_class %} active{% endblock %}
{% block content %}
+ {% include 'dashboard/includes/_filters.html' %}
{% if products %}
- {% include 'dashboard/includes/_filters.html' %}
<div class="row">
<div class="col s12">
<div class="card">
diff --git a/templates/dashboard/staff/list.html b/templates/dashboard/staff/list.html
index ea398b1321..df13a55394 100644
--- a/templates/dashboard/staff/list.html
+++ b/templates/dashboard/staff/list.html
@@ -34,6 +34,7 @@
{% endblock %}
{% block content %}
+ {% include 'dashboard/includes/_filters.html' %}
{% if staff %}
<div class="card">
<div class="data-table-container">
@@ -41,10 +42,13 @@
<thead>
<tr>
<th>
- {% trans "Email" context "Customers table header" %}
+ {% trans "Email" context "Staff members table header" %}
</th>
<th class="wide">
- {% trans "Name" context "Customers table header" %}
+ {% trans "Name" context "Staff members table header" %}
+ </th>
+ <th>
+ {% trans "Location" context "Staff members table header" %}
</th>
</tr>
</thead>