diff --git a/lingo/migrations/0007_lingobasketlinkcell.py b/lingo/migrations/0007_lingobasketlinkcell.py new file mode 100644 index 0000000..4af84dd --- /dev/null +++ b/lingo/migrations/0007_lingobasketlinkcell.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0001_initial'), + ('data', '0005_auto_20150226_0903'), + ('lingo', '0006_transaction_status'), + ] + + operations = [ + migrations.CreateModel( + name='LingoBasketLinkCell', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('placeholder', models.CharField(max_length=20)), + ('order', models.PositiveIntegerField()), + ('slug', models.SlugField(verbose_name='Slug', blank=True)), + ('public', models.BooleanField(default=True, verbose_name='Public')), + ('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)), + ('page', models.ForeignKey(to='data.Page')), + ], + options={ + 'verbose_name': 'Basket Link', + }, + bases=(models.Model,), + ), + ] diff --git a/lingo/models.py b/lingo/models.py index 9a3479b..369e927 100644 --- a/lingo/models.py +++ b/lingo/models.py @@ -160,3 +160,31 @@ class LingoRecentTransactionsCell(CellBase): start_date__gte=timezone.now()-datetime.timedelta(days=7) ).order_by('-start_date') return recent_transactions_template.render(context) + + +@register_cell_class +class LingoBasketLinkCell(CellBase): + user_dependant = True + + class Meta: + verbose_name = _('Basket Link') + + @classmethod + def is_enabled(cls): + return Regie.objects.count() > 0 + + def is_relevant(self, context): + if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()): + return False + 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_link.html') + context['items'] = BasketItem.objects.filter( + user=context['request'].user, payment_date__isnull=True + ).exclude(cancellation_date__isnull=False) + context['total'] = sum([x.amount for x in context['items']]) + return basket_template.render(context)