Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Further refactoring of sort_by
michal71c993fd236f
diff --git a/saleor/core/templatetags/shop.py b/saleor/core/templatetags/shop.pyindex 78273c6416..598baa6e07 100644--- a/saleor/core/templatetags/shop.py+++ b/saleor/core/templatetags/shop.py@@ -7,7 +7,6 @@ except ImportError:from django.template import Libraryfrom django.utils.http import urlencode-from ...product.filters import DEFAULT_SORTregister = Library()@@ -28,15 +27,3 @@ def get_sort_by_url(context, field, descending=False):else:request_get['sort_by'] = fieldreturn '%s?%s' % (request.path, urlencode(request_get))--[email protected]_tag('category/_sort_by.html', takes_context=True)-def sort_by(context, attributes):- ctx = {- 'request': context['request'],- 'sort_by': (context['request'].GET.get('sort_by', DEFAULT_SORT)- .strip('-')),- 'sort_by_choices': attributes,- 'arrow_down': (context['request'].GET.get('sort_by', DEFAULT_SORT)- .startswith('-'))}- return ctxdiff --git a/saleor/product/views.py b/saleor/product/views.pyindex 3581c8671d..1a793226d8 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -127,8 +127,11 @@ def category_index(request, path, category_id):product_filter.qs, PAGINATE_BY, request.GET.get('page'))products_and_availability = list(products_with_availability(products_paginated, request.discounts, request.currency))+ sort_by = request.GET.get('sort_by', DEFAULT_SORT)ctx = {'category': category, 'filter': product_filter,'products': products_and_availability,'products_paginated': products_paginated,- 'sort_by_choices': SORT_BY_FIELDS}+ 'sort_by_choices': SORT_BY_FIELDS,+ 'sort_by_label': sort_by.strip('-'),+ 'is_descending': sort_by.startswith('-')}return TemplateResponse(request, 'category/index.html', ctx)diff --git a/templates/category/_sort_by.html b/templates/category/_sort_by.htmldeleted file mode 100644index 4f2f9a8cfc..0000000000--- a/templates/category/_sort_by.html+++ /dev/null@@ -1,51 +0,0 @@-{% load staticfiles %}-{% load i18n %}-{% load shop %}--<div class="sort-by">- <div class="click-area d-none"></div>- <button class="btn btn-link">- <div>- <span>- Sort by: - <strong>- {{ sort_by }}- </strong>- </span>- <div class="sort-order-icon">- {% if arrow_down %}- <svg data-src="{% static "assets/arrow_down.svg" %}">- {% else %}- <svg data-src="{% static "assets/arrow_up.svg" %}">- {% endif %}- </div>- </div>- </button>- <ul class="sort-list d-none">- {% for choice in sort_by_choices %}- <li>- <div class="row">- <div class="col-6">- Sort by: <strong>{{ choice.label }}</strong>- </div>- <div class="col-6">- <div>- <a href="{% get_sort_by_url choice.value %}">- <span>{% trans 'ascending' context 'sort by option' %}</span>- <div class="sort-order-icon float-right">- <img src="{% static "assets/arrow_up.svg" %}">- </div>- </a>- <a href="{% get_sort_by_url choice.value descending=True %}">- <span>{% trans 'descending' context 'sort by option' %}</span>- <div class="sort-order-icon float-right">- <img src="{% static "assets/arrow_down.svg" %}">- </div>- </a>- </div>- </div>- </div>- </li>- {% endfor %}- </ul>-</div>diff --git a/templates/category/index.html b/templates/category/index.htmlindex 4c8a134377..5d1018c3fa 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -44,7 +44,53 @@<span class="filters-menu__label d-sm-none">Filters</span></div><div class="col-6 col-md-10 col-lg-6">- {% sort_by sort_by_choices %}+ <div class="sort-by">+ <div class="click-area d-none"></div>+ <button class="btn btn-link">+ <div>+ <span>+ Sort by: + <strong>+ {{ sort_by_label }}+ </strong>+ </span>+ <div class="sort-order-icon">+ {% if is_descending %}+ <svg data-src="{% static "assets/arrow_down.svg" %}">+ {% else %}+ <svg data-src="{% static "assets/arrow_up.svg" %}">+ {% endif %}+ </div>+ </div>+ </button>+ <ul class="sort-list d-none">+ {% for choice in sort_by_choices %}+ <li>+ <div class="row">+ <div class="col-6">+ Sort by: <strong>{{ choice.label }}</strong>+ </div>+ <div class="col-6">+ <div>+ <a href="{% get_sort_by_url choice.value %}">+ <span>{% trans 'ascending' context 'sort by option' %}</span>+ <div class="sort-order-icon float-right">+ <img src="{% static "assets/arrow_up.svg" %}">+ </div>+ </a>+ <a href="{% get_sort_by_url choice.value descending=True %}">+ <span>{% trans 'descending' context 'sort by option' %}</span>+ <div class="sort-order-icon float-right">+ <img src="{% static "assets/arrow_down.svg" %}">+ </div>+ </a>+ </div>+ </div>+ </div>+ </li>+ {% endfor %}+ </ul>+ </div></div></div></div>