Browse files

Cherry picked and merged 826caa8: 'Fixed sorting handling. The sortin…

…g template uses the same session for fulltext search and common search, but if SOLR is used, the fulltext needs different sorting parameter.'
  • Loading branch information...
1 parent 653a27e commit 67bab79c3d6353a5fd6e064399a4f9e90f0841f7 @naro naro committed with Jun 4, 2012
Showing with 32 additions and 15 deletions.
  1. +14 −0 lfs/catalog/settings.py
  2. +6 −1 lfs/catalog/utils.py
  3. +1 −1 lfs/catalog/views.py
  4. +8 −4 lfs/core/templatetags/lfs_tags.py
  5. +1 −1 lfs/portlet/models/filter.py
  6. +1 −7 lfs/search/views.py
  7. +1 −1 setup.py
View
14 lfs/catalog/settings.py
@@ -146,3 +146,17 @@
THUMBNAIL_SIZES = getattr(settings, 'LFS_THUMBNAIL_SIZES', ((60, 60), (100, 100), (200, 200), (300, 300), (400, 400)))
DELETE_FILES = getattr(settings, "LFS_DELETE_FILES", True)
DELETE_IMAGES = getattr(settings, "LFS_DELETE_IMAGES", True)
+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
@@ -486,7 +487,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
@@ -346,8 +346,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
@@ -24,6 +24,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
@@ -103,7 +104,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)
@@ -209,9 +215,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
@@ -35,7 +35,7 @@
'django-lfstheme == dev',
'django-pagination == 1.0.7',
'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',

0 comments on commit 67bab79

Please sign in to comment.