Skip to content

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

Move render_sorting_header template tag to dashboard

Anna Siwik90d2bcbf976b
diff --git a/saleor/core/templatetags/shop.py b/saleor/core/templatetags/shop.py
index 6d4e857902..88e993dce7 100644
--- a/saleor/core/templatetags/shop.py
+++ b/saleor/core/templatetags/shop.py
@@ -1,4 +1,3 @@
-from django.contrib.staticfiles.templatetags.staticfiles import static
from django.template import Library
from django.utils.http import urlencode
@@ -14,41 +13,3 @@ def get_sort_by_url(context, field, descending=False):
else:
request_get['sort_by'] = field
return '%s?%s' % (request.path, urlencode(request_get))
-
-
- 'dashboard/includes/_sorting_header.html', takes_context=True)
-def render_sorting_header(context, field, label, is_wide=False):
- """This template tag renders table sorting header."""
- request = context['request']
- request_get = request.GET.copy()
- sort_by = request_get.get('sort_by')
-
- # path to icon indicating applied sorting
- sorting_icon = ''
-
- # flag which determines if active sorting is on field
- is_active = False
-
- if sort_by:
- if field == sort_by:
- # enable ascending sort
- # new_sort_by is used to construct a link with already toggled
- # sort_by value
- new_sort_by = '-%s' % field
- sorting_icon = static('/images/arrow_up_icon.svg')
- is_active = True
- else:
- # enable descending sort
- new_sort_by = field
- if field == sort_by.strip('-'):
- sorting_icon = static('/images/arrow_down_icon.svg')
- is_active = True
- else:
- new_sort_by = field
-
- request_get['sort_by'] = new_sort_by
- return {
- 'url': '%s?%s' % (request.path, request_get.urlencode()),
- 'is_active': is_active, 'sorting_icon': sorting_icon, 'label': label,
- 'is_wide': is_wide}
diff --git a/saleor/dashboard/templatetags/utils.py b/saleor/dashboard/templatetags/utils.py
index 898892ed76..9f868f0175 100644
--- a/saleor/dashboard/templatetags/utils.py
+++ b/saleor/dashboard/templatetags/utils.py
@@ -3,6 +3,7 @@ from json import dumps
from urllib.parse import urlencode
from django import forms
+from django.contrib.staticfiles.templatetags.staticfiles import static
from django.template import Library
from django_filters.fields import RangeField
from versatileimagefield.widgets import VersatileImagePPOIClickWidget
@@ -115,3 +116,40 @@ def serialize_messages(context):
for i, message in enumerate(messages):
data[i] = str(message)
return dumps(data)
+
+
+ 'dashboard/includes/_sorting_header.html', takes_context=True)
+def render_sorting_header(context, field, label, is_wide=False):
+ """This template tag renders table sorting header."""
+ request = context['request']
+ request_get = request.GET.copy()
+ sort_by = request_get.get('sort_by')
+
+ # path to icon indicating applied sorting
+ sorting_icon = ''
+
+ # flag which determines if active sorting is on field
+ is_active = False
+
+ if sort_by:
+ is_active = True
+ if field == sort_by:
+ # enable ascending sort
+ # new_sort_by is used to construct a link with already toggled
+ # sort_by value
+ new_sort_by = '-%s' % field
+ sorting_icon = static('/images/arrow_up_icon.svg')
+ else:
+ # enable descending sort
+ new_sort_by = field
+ if field == sort_by.strip('-'):
+ sorting_icon = static('/images/arrow_down_icon.svg')
+ else:
+ new_sort_by = field
+
+ request_get['sort_by'] = new_sort_by
+ return {
+ 'url': '%s?%s' % (request.path, request_get.urlencode()),
+ 'is_active': is_active, 'sorting_icon': sorting_icon, 'label': label,
+ 'is_wide': is_wide}
diff --git a/templates/dashboard/category/detail.html b/templates/dashboard/category/detail.html
index 471d194c04..353e3c153b 100644
--- a/templates/dashboard/category/detail.html
+++ b/templates/dashboard/category/detail.html
@@ -2,7 +2,6 @@
{% load i18n %}
{% load mptt_tags %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/templates/dashboard/category/list.html b/templates/dashboard/category/list.html
index f7067c029c..5400362f09 100644
--- a/templates/dashboard/category/list.html
+++ b/templates/dashboard/category/list.html
@@ -2,7 +2,6 @@
{% load i18n %}
{% load mptt_tags %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/templates/dashboard/customer/list.html b/templates/dashboard/customer/list.html
index 08deb29590..080c4a755c 100644
--- a/templates/dashboard/customer/list.html
+++ b/templates/dashboard/customer/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load prices_i18n %}
-{% load render_sorting_header from shop %}
{% load materializecss %}
{% load utils %}
diff --git a/templates/dashboard/discount/sale/list.html b/templates/dashboard/discount/sale/list.html
index ef75d73afe..c8076f2829 100644
--- a/templates/dashboard/discount/sale/list.html
+++ b/templates/dashboard/discount/sale/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load prices_i18n %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load materializecss %}
{% load utils %}
diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.html
index 28221e37a5..993f4f629f 100644
--- a/templates/dashboard/discount/voucher/list.html
+++ b/templates/dashboard/discount/voucher/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load prices_i18n %}
-{% load render_sorting_header from shop %}
{% load materializecss %}
{% load utils %}
{% load static %}
diff --git a/templates/dashboard/group/list.html b/templates/dashboard/group/list.html
index f808901ebb..52818b5b23 100644
--- a/templates/dashboard/group/list.html
+++ b/templates/dashboard/group/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/templates/dashboard/includes/_orders_table.html b/templates/dashboard/includes/_orders_table.html
index d35b150fec..3d5f327447 100644
--- a/templates/dashboard/includes/_orders_table.html
+++ b/templates/dashboard/includes/_orders_table.html
@@ -1,6 +1,5 @@
{% load i18n %}
{% load prices_i18n %}
-{% load render_sorting_header from shop %}
{% load status %}
<div class="data-table-container">
diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.html
index 3a74184ea7..d6ee41b28b 100644
--- a/templates/dashboard/product/list.html
+++ b/templates/dashboard/product/list.html
@@ -2,7 +2,6 @@
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load product_first_image from product_images %}
{% load utils %}
diff --git a/templates/dashboard/product/product_attribute/list.html b/templates/dashboard/product/product_attribute/list.html
index ac63faa574..1ab5f5f44d 100644
--- a/templates/dashboard/product/product_attribute/list.html
+++ b/templates/dashboard/product/product_attribute/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/templates/dashboard/product/product_class/list.html b/templates/dashboard/product/product_class/list.html
index 9d3d25709c..c3b5d2b790 100644
--- a/templates/dashboard/product/product_class/list.html
+++ b/templates/dashboard/product/product_class/list.html
@@ -2,7 +2,6 @@
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/templates/dashboard/product/stock_location/list.html b/templates/dashboard/product/stock_location/list.html
index cc7355631a..3763a4ddb4 100644
--- a/templates/dashboard/product/stock_location/list.html
+++ b/templates/dashboard/product/stock_location/list.html
@@ -1,7 +1,6 @@
{% extends 'dashboard/base.html' %}
{% load i18n %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/templates/dashboard/shipping/list.html b/templates/dashboard/shipping/list.html
index e622061a5b..b9e5fcae8c 100644
--- a/templates/dashboard/shipping/list.html
+++ b/templates/dashboard/shipping/list.html
@@ -1,7 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load prices_i18n %}
-{% load render_sorting_header from shop %}
{% load status %}
{% load utils %}
{% load static %}
diff --git a/templates/dashboard/staff/list.html b/templates/dashboard/staff/list.html
index 9ca233ee08..8e07294aa3 100644
--- a/templates/dashboard/staff/list.html
+++ b/templates/dashboard/staff/list.html
@@ -2,7 +2,6 @@
{% load i18n %}
{% load prices_i18n %}
{% load materializecss %}
-{% load render_sorting_header from shop %}
{% load staticfiles %}
{% load utils %}
diff --git a/tests/dashboard/test_templatetags.py b/tests/dashboard/test_templatetags.py
index 9395127441..9bd8fb5b30 100644
--- a/tests/dashboard/test_templatetags.py
+++ b/tests/dashboard/test_templatetags.py
@@ -2,8 +2,8 @@ import pytest
from django.urls import reverse
-from saleor.core.templatetags.shop import (
- get_sort_by_url, render_sorting_header)
+from saleor.core.templatetags.shop import get_sort_by_url
+from saleor.dashboard.templatetags.utils import render_sorting_header
def test_sort_by_url_ascending(admin_client, default_category):