Skip to content

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

Add pagination

michal597e9a240119
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index c1def18fc0..939908976a 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -6,7 +6,9 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy
+from ...core.utils import get_paginator_items
from ...product.models import Category
+from ...settings import DASHBOARD_PAGINATE_BY
from ..views import staff_member_required
from .forms import CategoryForm
@@ -21,6 +23,8 @@ 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()
+ categories = get_paginator_items(
+ categories, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {'categories': categories, 'path': path, 'root': root}
return TemplateResponse(request, 'dashboard/category/list.html', ctx)
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index e620aff387..51bee373b2 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -5,9 +5,10 @@ from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.contrib.auth.decorators import permission_required
-from ..views import staff_member_required
from ...core.utils import get_paginator_items
from ...userprofile.models import User
+from ...settings import DASHBOARD_PAGINATE_BY
+from ..views import staff_member_required
@staff_member_required
@@ -20,7 +21,8 @@ def customer_list(request):
.annotate(
num_orders=Count('orders', distinct=True),
last_order=Max('orders', distinct=True)))
- customers = get_paginator_items(customers, 30, request.GET.get('page'))
+ customers = get_paginator_items(
+ customers, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {'customers': customers}
return TemplateResponse(request, 'dashboard/customer/list.html', ctx)
diff --git a/saleor/dashboard/discount/views.py b/saleor/dashboard/discount/views.py
index fccdf69309..69e408e86c 100644
--- a/saleor/dashboard/discount/views.py
+++ b/saleor/dashboard/discount/views.py
@@ -5,7 +5,9 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy
+from ...core.utils import get_paginator_items
from ...discount.models import Sale, Voucher
+from ...settings import DASHBOARD_PAGINATE_BY
from ..views import staff_member_required
from . import forms
@@ -14,6 +16,8 @@ from . import forms
@permission_required('discount.view_sale')
def sale_list(request):
sales = Sale.objects.prefetch_related('products')
+ sales = get_paginator_items(
+ sales, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {'sales': sales}
return TemplateResponse(request, 'dashboard/discount/sale/list.html', ctx)
@@ -57,6 +61,8 @@ def sale_delete(request, pk):
@permission_required('discount.view_voucher')
def voucher_list(request):
vouchers = Voucher.objects.select_related('product', 'category')
+ vouchers = get_paginator_items(
+ vouchers, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {'vouchers': vouchers}
return TemplateResponse(
request, 'dashboard/discount/voucher/list.html', ctx)
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 629f2b4b4d..5ac2cb6a71 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -16,6 +16,7 @@ from ...order import OrderStatus
from ...order.models import Order, OrderedItem, OrderNote
from ...product.models import ProductVariant
from ...userprofile.i18n import AddressForm
+from ...settings import DASHBOARD_PAGINATE_BY
from ..order.forms import OrderFilterForm
from ..views import staff_member_required
from .forms import (CancelGroupForm, CancelItemsForm, CancelOrderForm,
@@ -29,16 +30,16 @@ from .forms import (CancelGroupForm, CancelItemsForm, CancelOrderForm,
def order_list(request):
orders_all = Order.objects.prefetch_related(
'groups', 'payments', 'groups__items', 'user')
- active_status = request.GET.get('status')
- if active_status:
- orders = orders_all.filter(status=active_status)
+ status = request.GET.get('status')
+ if status:
+ orders = orders_all.filter(status=status)
else:
orders = orders_all.all()
- page = get_paginator_items(orders, 20, request.GET.get('page'))
+ orders = get_paginator_items(
+ orders, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
form = OrderFilterForm(
- request.POST or None, initial={'status': active_status or None})
- ctx = {'object_list': page.object_list, 'orders_all': orders_all.exists(),
- 'page_obj': page, 'is_paginated': page.has_other_pages(),
+ request.POST or None, initial={'status': status or None})
+ ctx = {'orders': orders,
'form': form}
return TemplateResponse(request, 'dashboard/order/list.html', ctx)
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 96034a723c..0d4c3a30d3 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -15,6 +15,7 @@ from ...product.models import (
Stock, StockLocation)
from ...product.utils import get_availability
from ..views import staff_member_required, superuser_required
+from ...settings import DASHBOARD_PAGINATE_BY
from . import forms
@@ -25,7 +26,8 @@ def product_class_list(request):
form = forms.ProductClassForm(request.POST or None)
if form.is_valid():
return redirect('dashboard:product-class-add')
- classes = get_paginator_items(classes, 30, request.GET.get('page'))
+ classes = get_paginator_items(
+ classes, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
classes.object_list = [
(pc.pk, pc.name, pc.has_variants, pc.product_attributes.all(),
pc.variant_attributes.all())
@@ -104,7 +106,8 @@ def product_list(request):
if form.is_valid():
return redirect(
'dashboard:product-add', class_pk=form.cleaned_data['product_cls'])
- products = get_paginator_items(products, 30, request.GET.get('page'))
+ products = get_paginator_items(
+ products, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {
'form': form, 'products': products, 'product_classes': product_classes}
return TemplateResponse(request, 'dashboard/product/list.html', ctx)
@@ -448,10 +451,13 @@ def attribute_list(request):
attributes = [
(attribute.pk, attribute.name, attribute.values.all())
for attribute in ProductAttribute.objects.prefetch_related('values')]
+ attributes = get_paginator_items(
+ attributes, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
+ ctx = {'attributes': attributes}
return TemplateResponse(
request,
'dashboard/product/product_attribute/list.html',
- {'attributes': attributes})
+ ctx)
@superuser_required
@@ -509,6 +515,8 @@ def attribute_delete(request, pk):
@permission_required('product.view_stock_location')
def stock_location_list(request):
stock_locations = StockLocation.objects.all()
+ stock_locations = get_paginator_items(
+ stock_locations, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {'locations': stock_locations}
return TemplateResponse(
request,
diff --git a/saleor/dashboard/shipping/views.py b/saleor/dashboard/shipping/views.py
index fae8e83a0a..c4c7549b52 100644
--- a/saleor/dashboard/shipping/views.py
+++ b/saleor/dashboard/shipping/views.py
@@ -6,16 +6,17 @@ from django.template.response import TemplateResponse
from django.utils.translation import pgettext_lazy
from ...core.utils import get_paginator_items
-
from ...shipping.models import ShippingMethod
from ..views import superuser_required
+from ...settings import DASHBOARD_PAGINATE_BY
from .forms import ShippingMethodForm, ShippingMethodCountryFormSet
@superuser_required
def shipping_method_list(request):
methods = ShippingMethod.objects.prefetch_related('price_per_country').all()
- methods = get_paginator_items(methods, 30, request.GET.get('page'))
+ methods = get_paginator_items(
+ methods, DASHBOARD_PAGINATE_BY, request.GET.get('page'))
ctx = {'shipping_methods': methods}
return TemplateResponse(request, 'dashboard/shipping/list.html', ctx)
diff --git a/saleor/settings.py b/saleor/settings.py
index d78ba84cc1..db4517ef39 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -269,6 +269,7 @@ LOW_STOCK_THRESHOLD = 10
MAX_CART_LINE_QUANTITY = os.environ.get('MAX_CART_LINE_QUANTITY', 50)
PAGINATE_BY = 16
+DASHBOARD_PAGINATE_BY = 30
BOOTSTRAP3 = {
'set_placeholder': False,
diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.html
index 2ea58a93f7..939bf88aa7 100644
--- a/templates/dashboard/category/list.html
+++ b/templates/dashboard/category/list.html
@@ -3,6 +3,7 @@
{% load mptt_tags %}
{% load materializecss %}
{% load staticfiles %}
+{% load utils %}
{% block title %}{% trans "Categories" context "Category list page title" %} - {{ block.super }}{% endblock %}
@@ -119,6 +120,7 @@
</li>
{% endfor %}
</ul>
+ {% paginate categories %}
{% else %}
<div class="not-found">
{% if root %}
diff --git a/templates/dashboard/customer/list.html b/templates/dashboard/customer/list.html
index 368fc58740..b791b5a49c 100644
--- a/templates/dashboard/customer/list.html
+++ b/templates/dashboard/customer/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}
+{% load utils %}
{% block title %}
{% trans "Customers" context "Dashboard customers list" %} - {{ block.super }}
@@ -86,5 +87,5 @@
</p>
</div>
{% endif %}
- {% include "dashboard/includes/_pagination.html" with page_obj=customers %}
+ {% paginate customers %}
{% endblock %}
diff --git a/templates/dashboard/discount/sale/list.html b/templates/dashboard/discount/sale/list.html
index c5fdb2bd32..e3ed043985 100644
--- a/templates/dashboard/discount/sale/list.html
+++ b/templates/dashboard/discount/sale/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}
+{% load utils %}
{% block title %}
{% trans "Sales" %} - {{ block.super }}
@@ -65,5 +66,5 @@
</table>
</div>
</div>
- {% include "dashboard/includes/_pagination.html" %}
+ {% paginate sales %}
{% endblock %}
diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.html
index 5385fd6922..62dba7aff1 100644
--- a/templates/dashboard/discount/voucher/list.html
+++ b/templates/dashboard/discount/voucher/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}
+{% load utils %}
{% block title %}
{% trans "Vouchers" context "Dashboard vouchers list" %} - {{ block.super }}
@@ -107,5 +108,5 @@
</table>
</div>
</div>
- {% include "dashboard/includes/_pagination.html" %}
+ {% paginate vouchers %}
{% endblock %}
diff --git a/templates/dashboard/order/list.html b/templates/dashboard/order/list.html
index 70734b10f4..3b56d7afa4 100644
--- a/templates/dashboard/order/list.html
+++ b/templates/dashboard/order/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load status %}
+{% load utils %}
{% block title %}{% trans "Orders" context "Dashboard orders list" %} - {{ block.super }}{% endblock %}
@@ -16,14 +17,14 @@
{% endblock %}
{% block content %}
- {% if orders_all %}
+ {% if orders %}
{% include "dashboard/includes/_status_filters.html" %}
- {% if object_list %}
+ {% if orders %}
<div class="card">
- {% include "dashboard/includes/_orders_table.html" with orders=object_list %}
+ {% include "dashboard/includes/_orders_table.html" with orders=orders %}
</div>
<div class="row">
- {% include "dashboard/includes/_pagination.html" %}
+ {% paginate orders %}
</div>
{% else %}
<div class="not-found">
diff --git a/templates/dashboard/product/product_attribute/detail.html b/templates/dashboard/product/product_attribute/detail.html
index 5823ab1b2c..284cd4f0a6 100644
--- a/templates/dashboard/product/product_attribute/detail.html
+++ b/templates/dashboard/product/product_attribute/detail.html
@@ -20,7 +20,7 @@
</li>
<li class="back-mobile">
<a href="{% url 'dashboard:product-attributes' %}">
- <i class="material-icons">arrow_back</i>
+ <svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />
</a>
</li>
<li>
@@ -53,7 +53,7 @@
</a>
</div>
</div>
- </div>
+ </div>
<div class="col m12 l9">
<div class="card">
<div class="card-content">
diff --git a/templates/dashboard/product/product_attribute/list.html b/templates/dashboard/product/product_attribute/list.html
index 73719ed502..8156e1892a 100644
--- a/templates/dashboard/product/product_attribute/list.html
+++ b/templates/dashboard/product/product_attribute/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load materializecss %}
{% load staticfiles %}
+{% load utils %}
{% block title %}
{% trans "Attributes" context "Dashboard attributes list" %} - {{ block.super }}
@@ -46,6 +47,7 @@
</li>
{% endfor %}
</ul>
+ {% paginate attributes %}
{% else %}
<div class="not-found">
<p class="grey-text">
diff --git a/templates/dashboard/product/product_class/list.html b/templates/dashboard/product/product_class/list.html
index d40ba5fcbd..6ae59c6265 100644
--- a/templates/dashboard/product/product_class/list.html
+++ b/templates/dashboard/product/product_class/list.html
@@ -3,6 +3,7 @@
{% load prices_i18n %}
{% load materializecss %}
{% load staticfiles %}
+{% load utils %}
{% block title %}
{% trans "Product types" context "Dashboard product types list" %} - {{ block.super }}
@@ -42,7 +43,7 @@
{{ name }}
</span>
<p class="list-item-desc">
- {% trans "Variants" context "Dashboard variants" %}:
+ {% trans "Variants" context "Dashboard variants" %}:
{% if has_variants %}
{% trans "Yes" %}
{% else %}
@@ -59,7 +60,7 @@
</li>
{% endfor %}
</ul>
- {% include "dashboard/includes/_pagination.html" with page_obj=product_classes %}
+ {% paginate product_classes %}
{% else %}
<div class="not-found">
<p class="grey-text">
diff --git a/templates/dashboard/product/stock_location/list.html b/templates/dashboard/product/stock_location/list.html
index aa6dca2c99..9734191f84 100644
--- a/templates/dashboard/product/stock_location/list.html
+++ b/templates/dashboard/product/stock_location/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load materializecss %}
{% load staticfiles %}
+{% load utils %}
{% block title %}
{% trans "Stock locations" context "Dashboard stock location" %} - {{ block.super }}
@@ -44,6 +45,7 @@
</li>
{% endfor %}
</ul>
+ {% paginate locations %}
{% else %}
<div class="not-found">
<p class="grey-text">
diff --git a/templates/dashboard/shipping/list.html b/templates/dashboard/shipping/list.html
index 3fc565fbb4..642b75337d 100644
--- a/templates/dashboard/shipping/list.html
+++ b/templates/dashboard/shipping/list.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load status %}
+{% load utils %}
{% block title %}
{% trans "Shipping methods" context "Dashboard shipping methods list" %} - {{ block.super }}
@@ -81,5 +82,5 @@
</div>
</div>
</div>
- {% include "dashboard/includes/_pagination.html" %}
+ {% paginate shipping_methods %}
{% endblock %}