36 lines
982 B
Python
36 lines
982 B
Python
from django.views.generic import TemplateView
|
|
from shop.filters import ProductFilter
|
|
from shop.models import Product
|
|
from web.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin, CartMixin
|
|
|
|
|
|
class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
|
|
template_name = "web/list_products.html"
|
|
queryset = Product.objects.all()
|
|
filter_class = ProductFilter
|
|
|
|
def get_context_data(self, **kwargs):
|
|
qs = self.get_queryset()
|
|
page = self.get_paginated_queryset(qs)
|
|
|
|
return {
|
|
"page": page,
|
|
"has_next_page": page.has_next(),
|
|
"has_previous_page": page.has_previous(),
|
|
}
|
|
|
|
|
|
class CartDropdown(TemplateView, CartMixin):
|
|
template_name = "components/cart/cart_navbar.html"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
cart = self.get_cart()
|
|
|
|
return {
|
|
"cart": cart,
|
|
}
|
|
|
|
|
|
list_products = ListProducts.as_view()
|
|
cart_dropdown = CartDropdown.as_view()
|