summaryrefslogtreecommitdiff
path: root/saleor/core/templatetags/shop.py
diff options
context:
space:
mode:
authormichal <michal.sipa@mirumee.com>2017-10-06 14:22:50 +0200
committermichal <michal.sipa@mirumee.com>2017-10-06 14:22:50 +0200
commit0ba195f2efdacb674c8ff7affbea353abbe2a936 (patch)
tree28ea4f3afb583e5f44a202a779aa655b8f1d19ce /saleor/core/templatetags/shop.py
parent0d11f7d0285b2dca7c7539049d01eafd8da6b99e (diff)
downloadsaleor-frontend-0ba195f2efdacb674c8ff7affbea353abbe2a936.tar.gz
saleor-frontend-0ba195f2efdacb674c8ff7affbea353abbe2a936.tar.bz2
saleor-frontend-0ba195f2efdacb674c8ff7affbea353abbe2a936.zip
Further refactoring of sort_by and sort_menu
Combine sort_by and sort_menu to one template and templatetag. Move templatetags to shop.py. Delete sort_menu.py and _sort_menu.html. Update index.html with new templatetags.
Diffstat (limited to 'saleor/core/templatetags/shop.py')
-rw-r--r--saleor/core/templatetags/shop.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/saleor/core/templatetags/shop.py b/saleor/core/templatetags/shop.py
index c1fdacb5..78273c64 100644
--- a/saleor/core/templatetags/shop.py
+++ b/saleor/core/templatetags/shop.py
@@ -7,6 +7,8 @@ except ImportError:
from django.template import Library
from django.utils.http import urlencode
+from ...product.filters import DEFAULT_SORT
+
register = Library()
@@ -18,8 +20,23 @@ def slice(items, group_size=1):
@register.simple_tag(takes_context=True)
-def get_sort_by_url(context, field):
+def get_sort_by_url(context, field, descending=False):
request = context['request']
request_get = request.GET.dict()
- request_get['sort_by'] = field
+ if descending:
+ request_get['sort_by'] = '-' + field
+ else:
+ request_get['sort_by'] = field
return '%s?%s' % (request.path, urlencode(request_get))
+
+
+@register.inclusion_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 ctx