Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#822 Create categories matrix page #829

Merged
merged 7 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions front/less/pages/catalog.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
@import "../common/utilities/mixins";

.category-block {
margin: 0 auto;

.Q(600; {
float: left;
width: 48%;
});

.Q(@sm; {
width: 32%;
});

&:not(:last-child) {
.Q(600; {
margin: 0 2% 0 0;
});
}
}

.catalog-list {
padding: 0 0 0 30px;

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ sorl-thumbnail==12.5.0
python-telegram-bot==11.1.0
sentry-sdk==0.7.2
https://github.com/selwin/django-user_agents/archive/master.zip
https://github.com/fidals/refarm-site/archive/0.5.7.zip
https://github.com/fidals/refarm-site/archive/0.5.10.zip
5 changes: 5 additions & 0 deletions shopelectro/tests/tests_selenium_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion shopelectro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down
38 changes: 34 additions & 4 deletions shopelectro/views/catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing
from collections import OrderedDict

from django import http
from django.conf import settings
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is little bit unclear. Let's create todo to document matrix structure

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
Expand Down
27 changes: 16 additions & 11 deletions templates/catalog/catalog.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
{% breadcrumbs_with_siblings page %}
<h1>{{ page.display.h1 }}</h1>

<ul class="catalog-list">
{% recursetree nodes %}
<li class="catalog-list-item">
<a href="{{ node.url }}" class="catalog-list-item">{{ node.name }}</a>
{% if not node.is_leaf_node %}
<ul class="catalog-list-children">
{{ children }}
<div class="container container-fluid">
<div class="row around-xs">
{% for root_name, children in matrix.items %}
<div class="category-block">
<h2>{{ root_name }}</h2>
<ul>
{% for category in children %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% for category in children %}
{% for child in children %}

up to you

Copy link
Contributor Author

@duker33 duker33 Apr 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already use category in the same place at STB. So, i'll leave like this for consistency.
category name is relevant too and has scope size only in 3 lines

<li class="second-level-category">
<a href="{{ category.url }}">{{ category.name }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
</div>
{% endfor %}
</div>
</div>

{% endblock %}