From 6c38b4628882782fee0c7e1448d4fe79ccf1c1cd Mon Sep 17 00:00:00 2001 From: duker Date: Sun, 28 Apr 2019 14:44:25 +0300 Subject: [PATCH] #822 Draft for categories matrix --- shopelectro/urls.py | 2 +- shopelectro/views/catalog.py | 27 +++++++++++++++++++++++---- templates/catalog/catalog.html | 25 ++++++++++++++----------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/shopelectro/urls.py b/shopelectro/urls.py index cdb59f6a..13e68637 100644 --- 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'^(?Probots\.txt)$', RobotsView.as_view()), custom_page_url(r'^(?Psearch)/$', views.Search.as_view()), - custom_page_url(r'^(?Pcatalog)/$', cached_2h(views.CategoryTree.as_view())), + custom_page_url(r'^(?Pcatalog)/$', cached_2h(views.CategoryMatrix.as_view())), custom_page_url(r'^(?Psitemap)/$', SitemapPage.as_view()), # these pages should show only actual state custom_page_url(r'^shop/(?Porder)/$', never_cache(views.OrderPage.as_view())), diff --git a/shopelectro/views/catalog.py b/shopelectro/views/catalog.py index 7584bd1a..954bf152 100644 --- a/shopelectro/views/catalog.py +++ b/shopelectro/views/catalog.py @@ -5,6 +5,7 @@ from django.shortcuts import render from django.urls import reverse from django.views.decorators.http import require_POST +from django.views.generic.list import ListView from django_user_agents.utils import get_user_agent from catalog import context @@ -12,15 +13,33 @@ 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 +class CategoryMatrix(ListView): + """The list of root categories.""" + + template_name = 'catalog/catalog.html' + context_object_name = 'categories' + + def get_queryset(self): + return ( + models.Category.objects + .bind_fields() + .active() + .filter(level=0) + .order_by('page__position', 'name') + ) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + return { + **context, + 'page': pages_models.CustomPage.objects.get(slug='catalog'), + } @set_csrf_cookie diff --git a/templates/catalog/catalog.html b/templates/catalog/catalog.html index cc4bdbeb..b5ac6ad9 100644 --- a/templates/catalog/catalog.html +++ b/templates/catalog/catalog.html @@ -7,16 +7,19 @@ {% breadcrumbs_with_siblings page %}

{{ page.display.h1 }}

-
    - {% recursetree nodes %} -
  • - {{ node.name }} - {% if not node.is_leaf_node %} -
      - {{ children }} +
      +
      + {% for root in categories %} +
      +

      {{ root.name }}

      + - {% endif %} - - {% endrecursetree %} -
    + + {% endfor %} + + + {% endblock %}