# Path: simplestore/cart/forms.py
# class AddToCartForm(forms.ModelForm):
#     class Meta:
#         model = CartItem
#         fields = [
#             'quantity'
#         ]
#         widgets = {
#             'quantity': forms.NumberInput(attrs={'class': 'full-width'})
#         }
# 
# Path: simplestore/products/models/product.py
# class ProductQuerySet(models.QuerySet):
# class ProductManager(models.Manager):
# class Product(models.Model):
#     class Meta:
#     def active(self):
#     def get_queryset(self):
#     def all(self):
#     def get_image_url(self):
#     def get_absolute_url(self):
#     def __str__(self):


from django.views.generic import ListView, DetailView
from simplestore.cart.forms import AddToCartForm
from .models.product import Product, Category



class CategoryDetailView(DetailView):
    model = Category
    slug_url_kwarg = 'category_slug'
    template_name = "category_detail.html"

    def get_context_data(self, **kwargs):
        context = super(CategoryDetailView, self).get_context_data(**kwargs)

        products = Product.objects.filter(
            category=self.get_object()
        ).prefetch_related('image')

        context.update({
            'products': products
        })
        return context


class ProductsListView(ListView):
    model = Product
    queryset = Product.objects.all().active().prefetch_related('image')
    template_name = "product_list.html"


class ProductDetailView(DetailView):

# Path: simplestore/cart/forms.py
# class AddToCartForm(forms.ModelForm):
#     class Meta:
#         model = CartItem
#         fields = [
#             'quantity'
#         ]
#         widgets = {
#             'quantity': forms.NumberInput(attrs={'class': 'full-width'})
#         }
# 
# Path: simplestore/products/models/product.py
# class ProductQuerySet(models.QuerySet):
# class ProductManager(models.Manager):
# class Product(models.Model):
#     class Meta:
#     def active(self):
#     def get_queryset(self):
#     def all(self):
#     def get_image_url(self):
#     def get_absolute_url(self):
#     def __str__(self):


# Path: simplestore/products/views.py
from django.views.generic import ListView, DetailView
from simplestore.cart.forms import AddToCartForm
from .models.product import Product, Category




class CategoryDetailView(DetailView):
    model = Category
    slug_url_kwarg = 'category_slug'
    template_name = "category_detail.html"

    def get_context_data(self, **kwargs):
        context = super(CategoryDetailView, self).get_context_data(**kwargs)

        products = Product.objects.filter(
            category=self.get_object()
        ).prefetch_related('image')

        context.update({
            'products': products
        })
        return context


class ProductsListView(ListView):
    model = Product
    queryset = Product.objects.all().active().prefetch_related('image')
    template_name = "product_list.html"


class ProductDetailView(DetailView):

    model = Product