Skip to content

Commit

Permalink
#550 Fork SortingCategoryPage class
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Aug 29, 2018
1 parent f2313ab commit 645782d
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ def merge_products_context(products):
class CategoryPage(catalog.CategoryPage):

def get_products(self) -> QuerySet:
sorting_index = int(self.kwargs.get('sorting', 0))
sorting_option = SortingOption(index=sorting_index)
return models.Product.actives.get_category_descendants(
self.object.model, ordering=(sorting_option.directed_field,)
self.object.model
)

def get_context_data(self, **kwargs):
Expand Down Expand Up @@ -278,11 +276,30 @@ def template_context(page, tag_titles, tags):
return page


class PaginationCategoryPage(DBContextCategoryPage):
class SortingCategoryPage(DBContextCategoryPage):

def get_products(self) -> QuerySet:
sorting_index = int(self.kwargs.get('sorting', 0))
sorting_option = SortingOption(index=sorting_index)
return models.Product.actives.get_category_descendants(
self.object.model, ordering=(sorting_option.directed_field,)
)

def get_sorting_index(self):
return int(self.kwargs.get('sorting', 0))

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
products = self.get_products()
return {
**context,
'products_data': merge_products_context(products),
'sort': self.get_sorting_index(),
}


class PaginationCategoryPage(SortingCategoryPage):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
products_on_page = int(self.request.GET.get(
Expand Down Expand Up @@ -312,10 +329,10 @@ def get_context_data(self, **kwargs):
'paginated_page': paginated_page,
'sorting_options': settings.CATEGORY_SORTING_OPTIONS.values(),
'limits': settings.CATEGORY_STEP_MULTIPLIERS,
'sort': self.get_sorting_index(),
}


# TODO make load_more one of the context classes
def load_more(request, category_slug, offset=0, limit=0, sorting=0, tags=None):
"""
Load more products of a given category.
Expand Down

0 comments on commit 645782d

Please sign in to comment.