fix public category filtering

This commit is contained in:
Thomas Steen Rasmussen 2016-05-17 21:55:09 +02:00
parent 1b0a8019aa
commit 407c8c31c4

View file

@ -90,15 +90,18 @@ class ShopIndexView(ListView):
if 'category' in self.request.GET: if 'category' in self.request.GET:
category = self.request.GET.get('category') category = self.request.GET.get('category')
# is this a public category
try: try:
categoryobj = ProductCategory.objects.get(slug=category) categoryobj = ProductCategory.objects.get(slug=category)
if not categoryobj.public: if not categoryobj.public:
raise Http404("Category not found") raise Http404("Category not found")
except ProductCategory.DoesNotExist: except ProductCategory.DoesNotExist:
raise Http404("Category not found") raise Http404("Category not found")
# filter products by the chosen category
context['products'] = context['products'].filter( context['products'] = context['products'].filter(
category__slug=category, category__slug=category
public=True,
) )
context['current_category'] = category context['current_category'] = category
context['categories'] = ProductCategory.objects.annotate( context['categories'] = ProductCategory.objects.annotate(