from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from .models import Product
from collections import defaultdict

@login_required
def index(request):
    products = Product.objects.all().order_by('category', 'name')
    grouped_products = defaultdict(list)
    for product in products:
        grouped_products[product.category].append(product)

    context = {
        'grouped_products': dict(grouped_products)
    }
    return render(request, 'core/index.html', context)

def article_detail(request):
    # This is a placeholder view to prevent errors
    return render(request, 'core/article_detail.html')