From 0b17e237d8516a8b3878ab131448fbf4cfb3e84a Mon Sep 17 00:00:00 2001 From: duker33 Date: Sun, 21 Apr 2019 07:00:58 +0300 Subject: [PATCH] #622 #619 Series fixes from prod (#628) * #622 Fix not shown item names at the search results * #619 Return 404 for category with no options * #622 Return 404 for categories with no active options * #622 Rm redundant CategoryTile tests * #622 Show mark column at the options list on product page * #622 Fix test * #622 Drop unused import * #622 Fix test --- stroyprombeton/context/catalog.py | 4 ++ stroyprombeton/models.py | 4 ++ stroyprombeton/tests/tests_selenium.py | 2 +- stroyprombeton/tests/tests_views.py | 91 +++++++++++--------------- stroyprombeton/views/catalog.py | 21 ++++-- templates/catalog/product.html | 2 + templates/search/items_list.html | 2 +- 7 files changed, 67 insertions(+), 59 deletions(-) diff --git a/stroyprombeton/context/catalog.py b/stroyprombeton/context/catalog.py index 0e59bb58..ec5fa92e 100644 --- a/stroyprombeton/context/catalog.py +++ b/stroyprombeton/context/catalog.py @@ -8,6 +8,7 @@ from functools import partial +from django import http from django.conf import settings from django.shortcuts import get_object_or_404 @@ -82,6 +83,9 @@ def context(self) -> typing.ContextDict: tags = FilteredTags(stb_models.Tag.objects.all(), self.request_data) options_ = options.Filtered(self.category, tags.qs(), self.request_data) + if not options_.qs(): + raise http.Http404('

В категории нет изделий BeautifulSoup: diff --git a/stroyprombeton/views/catalog.py b/stroyprombeton/views/catalog.py index 9825a39e..e0e7531e 100644 --- a/stroyprombeton/views/catalog.py +++ b/stroyprombeton/views/catalog.py @@ -1,7 +1,7 @@ from csv import writer as CSVWriter +from django import http from django.conf import settings -from django.http import HttpResponseBadRequest, StreamingHttpResponse from django.shortcuts import get_object_or_404, render from django.views.generic.detail import DetailView from django.views.generic.list import ListView @@ -24,7 +24,7 @@ def fetch_products(request): # @todo #451:60m Create middleware to for http errors. se2 # Middleware should transform http exceptions to http errors errors. except exception.Http400 as e: - return HttpResponseBadRequest(str(e)) + return http.HttpResponseBadRequest(str(e)) return render(request, 'catalog/options.html', context_.context()) @@ -57,7 +57,7 @@ def serialize_categories(categories): models.CategoryPage.objects.active() ) - response = StreamingHttpResponse( + response = http.StreamingHttpResponse( (writer.writerow(c) for c in categories), content_type="text/csv", ) @@ -205,12 +205,20 @@ def series_matrix(request, page='series'): def series(request, series_slug: str): series = get_object_or_404(models.Series.objects, slug=series_slug) - + options = series.options.active() + # @todo #619:60m Prevent code doubling in series views. + # Now series and series_matrix have doubled code. + # Possible solutions: + # - Use only one view for series and series+category. As category page does + # - Use view context system. Category view does it too. + # Those solutions don't except each other. + if not options: + raise http.Http404('

В секции нет изделийВ секции нет изделий + {% for group in tag_groups %} {% endfor %} @@ -66,6 +67,7 @@ {% for option in product.options.all %} + {% for group in tag_groups %} {% if item|hasattr_:'price' %}
Марка{{ group.name }}
{{ option.mark }} {% get_tag_name group option %} diff --git a/templates/search/items_list.html b/templates/search/items_list.html index fa1e8221..f083d3b5 100644 --- a/templates/search/items_list.html +++ b/templates/search/items_list.html @@ -15,7 +15,7 @@ - {{ item.catalog_name }} + {{ item.name }}