django-orchestra-test/orchestra/apps/payments/actions.py

30 lines
1.1 KiB
Python
Raw Normal View History

2014-09-10 16:53:09 +00:00
from django.contrib import messages
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from .methods import PaymentMethod
2014-09-10 16:53:09 +00:00
from .models import Transaction
def process_transactions(modeladmin, request, queryset):
2014-09-10 16:53:09 +00:00
processes = []
if queryset.exclude(state=Transaction.WAITTING_PROCESSING).exists():
msg = _("Selected transactions must be on '{state}' state")
messages.error(request, msg.format(state=Transaction.WAITTING_PROCESSING))
return
for method, transactions in queryset.group_by('source__method'):
if method is not None:
2014-09-10 16:53:09 +00:00
method = PaymentMethod.get_plugin(method)
procs = method.process(transactions)
processes += procs
if not processes:
return
opts = modeladmin.model._meta
context = {
'title': _("Huston, be advised"),
'action_name': _("Process"),
'processes': processes,
'opts': opts,
'app_label': opts.app_label,
}
return render(request, 'admin/payments/transaction/get_processes.html', context)