add "my basket" combo cell type (#6290)
This commit is contained in:
parent
174d5c28bb
commit
fadb044125
|
@ -17,10 +17,14 @@
|
|||
import eopayment
|
||||
from jsonfield import JSONField
|
||||
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from combo.data.models import CellBase
|
||||
from combo.data.library import register_cell_class
|
||||
|
||||
|
||||
SERVICES = [
|
||||
(eopayment.DUMMY, _('Dummy (for tests)')),
|
||||
|
@ -64,3 +68,20 @@ class BasketItem(models.Model):
|
|||
creation_date = models.DateTimeField(auto_now_add=True)
|
||||
cancellation_date = models.DateTimeField(null=True)
|
||||
payment_date = models.DateTimeField(null=True)
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class LingoBasketCell(CellBase):
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Basket')
|
||||
|
||||
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)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{% if total %}
|
||||
<h3>Basket</h3>
|
||||
<ul>
|
||||
{% for item in items %}
|
||||
<li>{{ item.subject }}: {{ item.amount }} €</li>
|
||||
{% endfor %}
|
||||
<li><strong>Total:</strong> {{ total }} €</li>
|
||||
</ul>
|
||||
{% endif %}
|
Reference in New Issue