Skip to content

Commit

Permalink
#550 Make context names shorten
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Sep 3, 2018
1 parent c626fcd commit 7343451
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions shopelectro/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def page(self):
return ModelPage.objects.get(slug=self.slug)


class ProductsListContext(AbstractPageContext, ABC):
class AbstractProductsListContext(AbstractPageContext, ABC):

super: 'ProductsListContext' = None
super: 'AbstractProductsListContext' = None

@property
def products(self) -> QuerySet:
Expand All @@ -140,8 +140,7 @@ def products(self) -> QuerySet:
raise NotImplementedError


# TODO - fork PageContext
class CategoryContext(ProductsListContext):
class Category(AbstractProductsListContext):
@property
def products(self) -> QuerySet:
return models.Product.actives.get_category_descendants(
Expand All @@ -168,7 +167,7 @@ def get_context_data(self):
}


class TaggedCategoryContext(ProductsListContext):
class TaggedCategory(AbstractProductsListContext):

def get_sorting_index(self):
return int(self.url_kwargs.get('sorting', 0))
Expand Down Expand Up @@ -216,7 +215,7 @@ def get_context_data(self):
}


class DBTemplateContext(AbstractPageContext):
class DBTemplate(AbstractPageContext):
"""Processes some page data fields as templates with each own context."""

@property
Expand Down Expand Up @@ -254,7 +253,7 @@ def get_context_data(self):
}


class SortingCategoryContext(ProductsListContext):
class SortingCategory(AbstractProductsListContext):

def get_sorting_index(self):
return int(self.url_kwargs.get('sorting', 0))
Expand All @@ -274,7 +273,7 @@ def get_context_data(self):
}


class PaginationCategoryContext(ProductsListContext):
class PaginationCategory(AbstractProductsListContext):

def get_products_count(self):
"""Calculate max products list size from request. List size depends on device type."""
Expand Down
10 changes: 5 additions & 5 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ def get_products(self) -> QuerySet:
def get_context_data(self, **kwargs):
"""Add sorting options and view_types in context."""
context_ = (
context.CategoryContext(self.kwargs, self.request)
| context.TaggedCategoryContext()
| context.SortingCategoryContext()
| context.PaginationCategoryContext()
| context.DBTemplateContext()
context.Category(self.kwargs, self.request)
| context.TaggedCategory()
| context.SortingCategory()
| context.PaginationCategory()
| context.DBTemplate()
)
return {
**super().get_context_data(**kwargs),
Expand Down

0 comments on commit 7343451

Please sign in to comment.