Repository: fidals/shopelectro

Issue:
Matrix view for the catalog page
---
Страница каталога https://www.shopelectro.ru/catalog/
Делаем по примеру https://www.220-volt.ru/catalog/ 

Три блока в строчке 
Кликабельный заголовок раздела  цвета и шрифты бери из карты товара. что бы не сливалось с подложкой. как сейчас
Первые три блока - Батарейки аккумуляторы блоки питания. выводим все подразделы. 
зарядные устройства новогодние товары измерительные приборы (по 7 подразделов второго уровня)
усилители звука беспроводные звонки радиоприемники  выводим все подразделы
Электротовары фонари автопреобразователи выводим все подразделы


From this doc:
https://docs.google.com/document/d/1y4xUQhQ4V_Ln5xwcEB2zMp7KTUQnkn9agKTTAU1z0-c/edit



Discussion:

Resolving patch:
diff --git a/shopelectro/urls.py b/shopelectro/urls.py
--- a/shopelectro/urls.py
+++ b/shopelectro/urls.py
@@ -103,7 +103,7 @@ def cache_page(arg):  # Ignore PyFlakesBear
     custom_page_url(r'^$', cached_2h(views.IndexPage.as_view()), {'page': ''}, name='index'),
     custom_page_url(r'^(?P<page>robots\.txt)$', RobotsView.as_view()),
     custom_page_url(r'^(?P<page>search)/$', views.Search.as_view()),
-    custom_page_url(r'^(?P<page>catalog)/$', cached_2h(views.CategoryTree.as_view())),
+    custom_page_url(r'^(?P<page>catalog)/$', cached_2h(views.category_matrix)),
     custom_page_url(r'^(?P<page>sitemap)/$', SitemapPage.as_view()),
     # these pages should show only actual state
     custom_page_url(r'^shop/(?P<page>order)/$', never_cache(views.OrderPage.as_view())),
diff --git a/shopelectro/views/catalog.py b/shopelectro/views/catalog.py
--- a/shopelectro/views/catalog.py
+++ b/shopelectro/views/catalog.py
@@ -1,4 +1,5 @@
 import typing
+from collections import OrderedDict
 
 from django import http
 from django.conf import settings
@@ -12,15 +13,44 @@
 from images.models import Image
 # can't do `import pages` because of django error.
 # Traceback: https://gist.github.com/duker33/685e8a9f59fc5dbd243e297e77aaca42
-from pages import views as pages_views
+from pages import models as pages_models, views as pages_views
 from shopelectro import context as se_context, models, request_data
 from shopelectro.exception import Http400
 from shopelectro.views.helpers import set_csrf_cookie
 
 
-# CATALOG VIEWS
-class CategoryTree(catalog.CategoryTree):
-    category_model = models.Category
+# block numeric indexes to limit
+MATRIX_BLOCKS_TO_LIMIT = [3, 5]
+MATRIX_BLOCK_SIZE = 7
+
+
+# @todo #822:60m  Create tests for the catalog matrix.
+#  This cases are would be good to test:
+#  - Matrix sorting by page position
+#  - Block items limiting
+def category_matrix(request, page: str):
+    assert page == 'catalog'
+    roots = (
+        models.Category.objects
+        .bind_fields()
+        .active()
+        .filter(level=0)
+        .order_by('page__position', 'name')
+    )
+    matrix = OrderedDict()
+    for i, root in enumerate(roots):
+        children = root.children.active()
+        # @todo #822:30m  Doc category matrix blocks.
+        matrix[root.name] = (
+            children
+            if i not in MATRIX_BLOCKS_TO_LIMIT
+            else children[:MATRIX_BLOCK_SIZE]
+        )
+    context_ = {
+        'matrix': matrix,
+        'page': pages_models.CustomPage.objects.get(slug=page),
+    }
+    return render(request, 'catalog/catalog.html', context_)
 
 
 @set_csrf_cookie


Test patch:
diff --git a/shopelectro/tests/tests_selenium_admin.py b/shopelectro/tests/tests_selenium_admin.py
--- a/shopelectro/tests/tests_selenium_admin.py
+++ b/shopelectro/tests/tests_selenium_admin.py
@@ -143,6 +143,11 @@ def test_login(self):
         admin_title = self.browser.find_element_by_id('site-name')
         self.assertIn(self.title_text, admin_title.text)
 
+    # @todo #822:30m  Resurrect admin price filter.
+    #  It's failing after fix changing `PriceRange.price_lookup` value.
+    #  Fix was here: https://github.com/fidals/refarm-site/pull/325
+    #  Just disable this filter for STB. It's not relevant there
+    @unittest.expectedFailure
     def test_product_price_filter(self):
         """
         Price filter is able to filter products by set range.