|
|
|
@ -1,24 +1,69 @@ |
|
|
|
from django.shortcuts import render, get_list_or_404, get_object_or_404 |
|
|
|
|
|
|
|
from django.contrib import auth |
|
|
|
|
|
|
|
from django.http import Http404 |
|
|
|
|
|
|
|
import json |
|
|
|
import json |
|
|
|
import decimal |
|
|
|
import decimal |
|
|
|
|
|
|
|
|
|
|
|
from django.views.generic import ListView |
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
from django.shortcuts import render |
|
|
|
|
|
|
|
from django.contrib import auth |
|
|
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
|
|
|
from django.views.generic import ListView, DetailView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .models import ( |
|
|
|
|
|
|
|
Manufacturer,Product,ProductCategory |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .forms import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# from cart.forms import CartAddProductForm |
|
|
|
class ManufactureListView(ListView): |
|
|
|
from .utils import * |
|
|
|
model = Manufacturer |
|
|
|
# from cart.cart import Cart |
|
|
|
template_name = 'products/manufacture_list.html' |
|
|
|
from .models import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductDetailsView(DetailView): |
|
|
|
|
|
|
|
model = Product |
|
|
|
|
|
|
|
template_name = 'products/product_detail.html' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductSearchView(ListView): |
|
|
|
class ProductSearchView(ListView): |
|
|
|
model = Product |
|
|
|
model = Product |
|
|
|
template_name = 'products/search.html' |
|
|
|
template_name = 'products/product_search.html' |
|
|
|
|
|
|
|
context_object_name = 'products' |
|
|
|
|
|
|
|
paginate_by = settings.DEFAULT_PAGE_AMMOUNT |
|
|
|
|
|
|
|
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): |
|
|
|
|
|
|
|
model = Product |
|
|
|
|
|
|
|
template_name = 'products/product_list.html' |
|
|
|
|
|
|
|
context_object_name = 'products' |
|
|
|
|
|
|
|
paginate_by = settings.DEFAULT_PAGE_AMMOUNT |
|
|
|
|
|
|
|
title = _('Список товаров') |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
def get_queryset(self): |
|
|
|
queryset = super().get_queryset() |
|
|
|
queryset = super().get_queryset() |
|
|
|
return queryset.filter(name__icontains=self.request) |
|
|
|
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 |
|
|
|
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductCategoryListView(ListView): |
|
|
|
|
|
|
|
model = ProductCategory |
|
|
|
|
|
|
|
template_name = 'products/product_category_list.html' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Uncomment for elasticsearch |
|
|
|
# Uncomment for elasticsearch |
|
|
|
|
|
|
|
|
|
|
|
@ -31,6 +76,7 @@ def serialize_decimal(obj): |
|
|
|
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 |
|
|
|
|