|
|
|
@ -7,6 +7,7 @@ from django.contrib import auth |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.views.generic import ListView, DetailView |
|
|
|
from django.views.generic import ListView, DetailView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from core.views import ProtectedListView |
|
|
|
from .models import ( |
|
|
|
from .models import ( |
|
|
|
Manufacturer,Product,ProductCategory |
|
|
|
Manufacturer,Product,ProductCategory |
|
|
|
) |
|
|
|
) |
|
|
|
@ -24,69 +25,57 @@ class ProductDetailsView(DetailView): |
|
|
|
template_name = 'products/product_detail.html' |
|
|
|
template_name = 'products/product_detail.html' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductSearchView(ListView): |
|
|
|
|
|
|
|
model = Product |
|
|
|
|
|
|
|
template_name = 'products/product_search.html' |
|
|
|
|
|
|
|
context_object_name = 'products' |
|
|
|
|
|
|
|
paginate_by = settings.DEFAULT_PAGE_AMOUNT |
|
|
|
|
|
|
|
title = _('Поиск товара') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
|
|
|
|
queryset = super().get_queryset() |
|
|
|
|
|
|
|
if self.kwargs.get('name'): |
|
|
|
|
|
|
|
queryset = queryset.filter(name__icontains=self.kwargs.get('name')) |
|
|
|
|
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, *, object_list=None, **kwargs): |
|
|
|
|
|
|
|
context = super().get_context_data(object_list=object_list, **kwargs) |
|
|
|
|
|
|
|
context['title'] = self.title + ":" + self.request.GET.get('name', '') |
|
|
|
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductListView(ListView): |
|
|
|
class ProductListView(ListView): |
|
|
|
model = Product |
|
|
|
model = Product |
|
|
|
|
|
|
|
form = ProductSearchForm |
|
|
|
template_name = 'products/product_list.html' |
|
|
|
template_name = 'products/product_list.html' |
|
|
|
context_object_name = 'products' |
|
|
|
context_object_name = 'products' |
|
|
|
paginate_by = settings.DEFAULT_PAGE_AMOUNT |
|
|
|
paginate_by = settings.DEFAULT_PAGE_AMOUNT |
|
|
|
title = _('Список товаров') |
|
|
|
title = _('Список товаров') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_title(self): |
|
|
|
|
|
|
|
if self.request.GET.get('name'): |
|
|
|
|
|
|
|
return _('Поиск товара') + ":" + self.request.GET.get('name') |
|
|
|
|
|
|
|
title = _('Список товаров') |
|
|
|
|
|
|
|
if self.request.resolver_match.kwargs.get('category_slug'): |
|
|
|
|
|
|
|
return title + ":" + self.request.resolver_match.kwargs.get('category_slug') |
|
|
|
|
|
|
|
return title |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
def get_queryset(self): |
|
|
|
queryset = super().get_queryset() |
|
|
|
queryset = super().get_queryset() |
|
|
|
|
|
|
|
if self.kwargs.get('name'): |
|
|
|
|
|
|
|
queryset = queryset.filter(name__icontains=self.kwargs.get('name')) |
|
|
|
return queryset |
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, *, object_list=None, **kwargs): |
|
|
|
def get_context_data(self, *, object_list=None, **kwargs): |
|
|
|
context = super().get_context_data(object_list=object_list, **kwargs) |
|
|
|
context = super().get_context_data(object_list=object_list, **kwargs) |
|
|
|
context['title'] = self.title |
|
|
|
context['title'] = self.get_title() |
|
|
|
return context |
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductCategoryListView(ListView): |
|
|
|
|
|
|
|
model = ProductCategory |
|
|
|
|
|
|
|
template_name = 'products/product_category_list.html' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Uncomment for elasticsearch |
|
|
|
# Uncomment for elasticsearch |
|
|
|
|
|
|
|
|
|
|
|
# from .layout import FacetedProductSearchForm |
|
|
|
# from .layout import FacetedProductSearchForm |
|
|
|
# from haystack.generic_views import FacetedSearchView as BaseFacetedSearchView |
|
|
|
# from haystack.generic_views import FacetedSearchView as BaseFacetedSearchView |
|
|
|
# from haystack.query import SearchQuerySet |
|
|
|
# from haystack.query import SearchQuerySet |
|
|
|
|
|
|
|
|
|
|
|
def serialize_decimal(obj): |
|
|
|
# def serialize_decimal(obj): |
|
|
|
if isinstance(obj, decimal.Decimal): |
|
|
|
# if isinstance(obj, decimal.Decimal): |
|
|
|
return str(obj) |
|
|
|
# return str(obj) |
|
|
|
return json.JSONEncoder.default(obj) |
|
|
|
# return json.JSONEncoder.default(obj) |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# |
|
|
|
def producerslist(request): |
|
|
|
# def producerslist(request): |
|
|
|
username = auth.get_user(request).username |
|
|
|
# username = auth.get_user(request).username |
|
|
|
# category = None |
|
|
|
# # category = None |
|
|
|
# categories = ProductCategory.objects.filter(level__lte=0) |
|
|
|
# # categories = ProductCategory.objects.filter(level__lte=0) |
|
|
|
# products = Product.objects.filter(is_active=True) |
|
|
|
# # products = Product.objects.filter(is_active=True) |
|
|
|
producers = Manufacturer.objects.filter(is_active=True) |
|
|
|
# producers = Manufacturer.objects.filter(is_active=True) |
|
|
|
# if category_slug: |
|
|
|
# # if category_slug: |
|
|
|
# category = get_object_or_404(ProductCategory, slug=category_slug) |
|
|
|
# # category = get_object_or_404(ProductCategory, slug=category_slug) |
|
|
|
# products = products.filter(category__in=category.get_descendants(include_self=True)) |
|
|
|
# # products = products.filter(category__in=category.get_descendants(include_self=True)) |
|
|
|
return render(request, 'products/list.html', locals()) |
|
|
|
# return render(request, 'products/list.html', locals()) |
|
|
|
|
|
|
|
|
|
|
|
# def categorieslist(request, producer_slug, category_slug=None): |
|
|
|
# def categorieslist(request, producer_slug, category_slug=None): |
|
|
|
# username = accounts_ext.get_user(request).username |
|
|
|
# username = accounts_ext.get_user(request).username |
|
|
|
|