fix: extracted all web related stuff to a new app
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from shop.filters import ProductFilter
|
||||
from shop.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin
|
||||
from shop.models import Product
|
||||
|
||||
|
||||
class IndexView(TemplateView):
|
||||
template_name = "web/index.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return {
|
||||
"title": "Shoppy",
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
products = self.get_paginated_queryset(qs)
|
||||
|
||||
return {
|
||||
"products": products,
|
||||
}
|
||||
|
||||
|
||||
class ProductDetail(TemplateView):
|
||||
template_name = "web/product_detail.html"
|
||||
|
||||
def get_context_data(self, pk, slug, **kwargs):
|
||||
product = get_object_or_404(Product, pk=pk)
|
||||
|
||||
return {
|
||||
"product": product,
|
||||
"title": product.name,
|
||||
"description": product.description,
|
||||
"image": product.images.first(),
|
||||
}
|
||||
|
||||
|
||||
index = IndexView.as_view()
|
||||
list_products = ListProducts.as_view()
|
||||
product_detail = ProductDetail.as_view()
|
||||
Reference in New Issue
Block a user