Skip to content

Commit

Permalink
fidals/refarm-site#208 Remove an excess argument from get_category_de…
Browse files Browse the repository at this point in the history
…scendants (#633)

* Remove excess ordering field from get_category_descendants

* Fix load_more
  • Loading branch information
ArtemijRodionov committed Nov 26, 2018
1 parent 2208ac6 commit ebfdca3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ ua-parser==0.8.0
user-agents==1.1.0
sorl-thumbnail==12.4a1
https://github.com/selwin/django-user_agents/archive/master.zip
https://github.com/fidals/refarm-site/archive/0.4.14.zip
https://github.com/fidals/refarm-site/archive/0.4.16.zip
2 changes: 1 addition & 1 deletion shopelectro/tests/tests_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def test_load_more_after_filtering(self):
self.load_more_products()
new_product_cards = len(self.browser.find_elements_by_class_name('product-card'))

self.assertEqual(new_product_cards, 50)
self.assertEqual(new_product_cards, 96)


class ProductPage(helpers.SeleniumTestCase):
Expand Down
10 changes: 7 additions & 3 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ def load_more(request, category_slug, offset=0, limit=0, sorting=0, tags=None):
category = get_object_or_404(models.CategoryPage, slug=category_slug).model
sorting_option = context.SortingOption(index=int(sorting))

all_products = models.Product.objects.active().get_category_descendants(
category, ordering=(sorting_option.directed_field,)
all_products = (
models.Product.objects
.active()
.get_category_descendants(category)
.order_by(sorting_option.directed_field)
)

if tags:
Expand All @@ -225,7 +228,8 @@ def load_more(request, category_slug, offset=0, limit=0, sorting=0, tags=None):
.filter(tags__in=tag_entities)
# Use distinct because filtering by QuerySet tags,
# that related with products by many-to-many relation.
.distinct(sorting_option.field)
# Add `id` because `sorting_option.directed_field` maybe not uniq.
.distinct('id', sorting_option.directed_field)
)

paginated = context.PaginatorLinks(
Expand Down

0 comments on commit ebfdca3

Please sign in to comment.