Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed sorting handling. The sorting template uses the same session fo…

…r fulltext search and common search, but if SOLR is used, the fulltext needs different sorting parameter.
  • Loading branch information...
commit 826caa8ef34ab8d7c09ed10b9a506a06fb3376d0 1 parent b7895dc
@naro naro authored committed
View
15 lfs/catalog/settings.py
@@ -144,3 +144,18 @@
PRODUCT_TEMPLATES = getattr(settings, 'PRODUCT_TEMPLATES', PRODUCT_TEMPLATES)
THUMBNAIL_SIZES = getattr(settings, 'LFS_THUMBNAIL_SIZES', ((60, 60), (100, 100), (200, 200), (300, 300), (400, 400)))
+
+if getattr(settings, 'SOLR_ENABLED', False):
+ SORTING_MAP = (
+ {'default': 'price', 'ftx': 'price asc', 'title': _('Price ascending')},
+ {'default': '-price', 'ftx': 'price desc', 'title': _('Price descending')},
+ {'default': 'name', 'ftx': 'name asc', 'title': _('Name ascending')},
+ {'default': '-name', 'ftx': 'name desc', 'title': _('Name descending')},
+ )
+else:
+ SORTING_MAP = (
+ {'default': 'price', 'ftx': 'price', 'title': _('Price ascending')},
+ {'default': '-price', 'ftx': '-price', 'title': _('Price descending')},
+ {'default': 'name', 'ftx': 'name', 'title': _('Name ascending')},
+ {'default': '-name', 'ftx': '-name', 'title': _('Name descending')},
+ )
View
7 lfs/catalog/utils.py
@@ -5,6 +5,7 @@
from django.conf import settings
from django.core.cache import cache
from django.db import connection
+from django.core.exceptions import FieldError
# import lfs
import lfs.catalog.models
@@ -505,7 +506,11 @@ def get_filtered_products_for_category(category, filters, price_filter, sorting)
products = lfs.catalog.models.Product.objects.filter(pk__in=matched_product_ids)
if sorting:
- products = products.order_by(sorting)
+ try:
+ products = products.order_by(sorting)
+ except FieldError:
+ # ignore invalid sort order which may be stored in the session
+ pass
return products
View
2  lfs/catalog/views.py
@@ -344,8 +344,8 @@ def category_products(request, slug, start=1, template_name="lfs/catalog/categor
default_sorting = settings.LFS_PRODUCTS_SORTING
except AttributeError:
default_sorting = "price"
-
sorting = request.session.get("sorting", default_sorting)
+
product_filter = request.session.get("product-filter", {})
product_filter = product_filter.items()
View
12 lfs/core/templatetags/lfs_tags.py
@@ -21,6 +21,7 @@
from lfs.catalog.settings import CATEGORY_VARIANT_CHEAPEST_PRICES
from lfs.catalog.settings import PRODUCT_WITH_VARIANTS
from lfs.catalog.settings import STANDARD_PRODUCT
+from lfs.catalog.settings import SORTING_MAP
from lfs.catalog.models import Product
from lfs.catalog.models import PropertyOption
from lfs.catalog.settings import PRODUCT_TYPE_LOOKUP
@@ -99,7 +100,12 @@ def sorting(context):
"""
"""
request = context.get("request")
- return {"current": request.session.get("sorting")}
+ sorting = request.session.get("sorting")
+ # prepare list of available sort options, sorted by SORTING_MAP_ORDER
+ sort_options = []
+ for item in SORTING_MAP:
+ sort_options.append(item)
+ return {"current": sorting, "sort_options": sort_options}
@register.inclusion_tag('lfs/catalog/breadcrumbs.html', takes_context=True)
@@ -181,9 +187,7 @@ def product_navigation(context, product):
"""Provides previous and next product links.
"""
request = context.get("request")
- sorting = request.session.get("sorting", "price")
- if sorting == "":
- sorting = "price"
+ sorting = request.session.get("sorting", 'price')
slug = product.slug
View
2  lfs/portlet/models/filter.py
@@ -28,7 +28,7 @@ def render(self, context):
"""Renders the portlet as html.
"""
request = context.get("request")
- sorting = request.session.get("sorting")
+ sorting = request.session.get("sorting", "price")
category = context.get("category")
if category is None:
View
8 lfs/search/views.py
@@ -63,13 +63,7 @@ def search(request, template_name="lfs/search/search_results.html"):
# Sorting
sorting = request.session.get("sorting")
if sorting:
- try:
- products = products.order_by(sorting)
- except FieldError:
- # this should not happen but I experienced it when
- # switching on/off lfs_solr which uses different
- # field specification for sorting but the same session key
- del request.session["sorting"]
+ products = products.order_by(sorting)
total = 0
if products:
View
2  setup.py
@@ -33,7 +33,7 @@
'django-pagination == 1.0.7',
'django-paypal == 0.1.2',
'django-portlets == 1.1.1',
- 'django-postal == 0.9',
+ 'django-postal == 0.92',
'django-reviews == 0.2.1',
'django-tagging == 0.3.1',
'lfs-contact == 1.0',
Please sign in to comment.
Something went wrong with that request. Please try again.