638 |
638 |
ordering = ['regie', 'extra_fee', 'subject']
|
639 |
639 |
|
640 |
640 |
@classmethod
|
641 |
|
def get_items_to_be_paid(cls, user):
|
|
641 |
def get_items_to_be_paid(cls, user, poll=False, raise_on_poll=False):
|
642 |
642 |
qs = cls.objects.filter(
|
643 |
643 |
user=user, payment_date__isnull=True, waiting_date__isnull=True, cancellation_date__isnull=True
|
644 |
644 |
)
|
645 |
|
for transaction in Transaction.objects.filter(items__in=qs):
|
646 |
|
if transaction.can_poll_backend():
|
647 |
|
transaction.poll_backend()
|
|
645 |
if poll:
|
|
646 |
for transaction in Transaction.objects.filter(items__in=qs):
|
|
647 |
if transaction.can_poll_backend():
|
|
648 |
if raise_on_poll:
|
|
649 |
raise NothingInCacheException
|
|
650 |
transaction.poll_backend()
|
648 |
651 |
return qs
|
649 |
652 |
|
650 |
653 |
def notify(self, status):
|
... | ... | |
1087 |
1090 |
|
1088 |
1091 |
def render(self, context):
|
1089 |
1092 |
basket_template = template.loader.get_template('lingo/combo/basket.html')
|
1090 |
|
items = BasketItem.get_items_to_be_paid(context['request'].user)
|
|
1093 |
items = BasketItem.get_items_to_be_paid(
|
|
1094 |
context['request'].user, poll=True, raise_on_poll=not context.get('synchronous')
|
|
1095 |
)
|
1091 |
1096 |
regies = {}
|
1092 |
1097 |
for item in items:
|
1093 |
1098 |
if not item.regie_id in regies:
|
... | ... | |
1112 |
1117 |
def is_enabled(cls):
|
1113 |
1118 |
return Regie.objects.exists()
|
1114 |
1119 |
|
1115 |
|
def get_transactions_queryset(self, context):
|
|
1120 |
def get_transactions_queryset(self, context, poll=False):
|
1116 |
1121 |
user = context['request'].user
|
1117 |
1122 |
# list transactions :
|
1118 |
1123 |
# * paid by the user
|
... | ... | |
1120 |
1125 |
qs = Transaction.objects.filter(models.Q(user=user) | models.Q(items__user=user)).filter(
|
1121 |
1126 |
start_date__gte=timezone.now() - datetime.timedelta(days=7)
|
1122 |
1127 |
)
|
1123 |
|
for transaction in qs:
|
1124 |
|
if transaction.can_poll_backend() and transaction.is_running():
|
1125 |
|
transaction.poll_backend()
|
|
1128 |
if poll:
|
|
1129 |
for transaction in qs:
|
|
1130 |
if transaction.can_poll_backend() and transaction.is_running():
|
|
1131 |
if not context.get('synchronous'):
|
|
1132 |
raise NothingInCacheException
|
|
1133 |
transaction.poll_backend()
|
1126 |
1134 |
return qs
|
1127 |
1135 |
|
1128 |
1136 |
def is_relevant(self, context):
|
... | ... | |
1132 |
1140 |
|
1133 |
1141 |
def render(self, context):
|
1134 |
1142 |
recent_transactions_template = template.loader.get_template('lingo/combo/recent_transactions.html')
|
1135 |
|
context['transactions'] = self.get_transactions_queryset(context).distinct().order_by('-start_date')
|
|
1143 |
context['transactions'] = (
|
|
1144 |
self.get_transactions_queryset(context, poll=True).distinct().order_by('-start_date')
|
|
1145 |
)
|
1136 |
1146 |
return recent_transactions_template.render(context)
|
1137 |
1147 |
|
1138 |
1148 |
|