cell: mark itself as irrelevant if the basket is empty

This commit is contained in:
Frédéric Péters 2015-02-16 17:11:54 +01:00
parent ed0f6a4f0f
commit 5774b3a669
1 changed files with 6 additions and 2 deletions

View File

@ -76,12 +76,16 @@ class LingoBasketCell(CellBase):
class Meta:
verbose_name = _('Basket')
def is_relevant(self, context):
items = BasketItem.objects.filter(
user=context['request'].user, payment_date__isnull=True
).exclude(cancellation_date__isnull=False)
return len(items) > 0
def render(self, context):
basket_template = template.loader.get_template('lingo/combo/basket.html')
context['items'] = BasketItem.objects.filter(
user=context['request'].user, payment_date__isnull=True
).exclude(cancellation_date__isnull=False)
if len(context['items']) == 0:
return ''
context['total'] = sum([x.amount for x in context['items']])
return basket_template.render(context)