From 7343451d447759e3f66d3b96507d8d50028cb89e Mon Sep 17 00:00:00 2001 From: duker Date: Mon, 3 Sep 2018 18:09:03 +0300 Subject: [PATCH] #550 Make context names shorten --- shopelectro/context.py | 15 +++++++-------- shopelectro/views/catalog.py | 10 +++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/shopelectro/context.py b/shopelectro/context.py index c8ee51cf..572e9a6b 100644 --- a/shopelectro/context.py +++ b/shopelectro/context.py @@ -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: @@ -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( @@ -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)) @@ -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 @@ -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)) @@ -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.""" diff --git a/shopelectro/views/catalog.py b/shopelectro/views/catalog.py index 520dcd0c..f8098f1f 100644 --- a/shopelectro/views/catalog.py +++ b/shopelectro/views/catalog.py @@ -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),