Deal with items that belong to no category

This commit is contained in:
Raphael Michel
2015-02-18 19:45:48 +01:00
parent fa405372b9
commit 03184bdbf2
3 changed files with 4 additions and 6 deletions

View File

@@ -35,7 +35,7 @@
{% csrf_token %}
{% for tup in items_by_category %}
<section>
<h3>{{ tup.0.name }}</h3>
{% if tup.0 %}<h3>{{ tup.0.name }}</h3>{% endif %}
{% for item in tup.1 %}
{% if item.has_variations %}
<div class="row-fluid product-row headline">

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -49,9 +49,10 @@ class EventIndex(EventViewMixin, CartDisplayMixin, TemplateView):
# Regroup those by category
context['items_by_category'] = sorted([
# a group is a tuple of a category and a list of items
(cat, [i for i in items if i.category_id == cat.identity])
(cat, [i for i in items if i.category == cat])
for cat in set([i.category for i in items]) # insert categories into a set for uniqueness
], key=lambda group: (group[0].position, group[0].pk)) # a set is unsorted, so sort again by category
# a set is unsorted, so sort again by category
], key=lambda group: (group[0].position, group[0].identity) if group[0] is not None else (0, ""))
context['cart'] = self.get_cart() if self.request.user.is_authenticated() else None
return context