From 5a354c61a0905cc379a77fa8ebcfea2545f20c33 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 2 Dec 2016 00:16:40 -0200 Subject: [PATCH] fetch transfers as well --- kfet/views.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index e8080774..b270a96d 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1331,10 +1331,10 @@ def history_json(request): opegroups_list = [] for opegroup in opegroups: opegroup_dict = { + 'type' : 'opegroup', 'id' : opegroup.id, 'amount' : opegroup.amount, 'at' : opegroup.at, - 'checkout_id': opegroup.checkout_id, 'is_cof' : opegroup.is_cof, 'comment' : opegroup.comment, 'opes' : [], @@ -1363,7 +1363,41 @@ def history_json(request): ope.canceled_by and ope.canceled_by.trigramme or None) opegroup_dict['opes'].append(ope_dict) opegroups_list.append(opegroup_dict) - return JsonResponse({ 'opegroups': opegroups_list }) + + for transfergroup in transfergroups: + if transfergroup.filtered_transfers: + transfergroup_dict = { + 'type': 'transfergroup', + 'id': transfergroup.id, + 'at': transfergroup.at, + 'comment': transfergroup.comment, + 'opes': [], + } + if request.user.has_perm('kfet.is_team'): + transfergroup_dict['valid_by__trigramme'] = ( + transfergroup.valid_by + and transfergroup.valid_by.trigramme + or None) + + for transfer in transfergroup.filtered_transfers: + transfer_dict = { + 'id': transfer.id, + 'amount': transfer.amount, + 'canceled_at': transfer.canceled_at, + 'from_acc': transfer.from_acc.trigramme, + 'to_acc': transfer.to_acc.trigramme, + } + if request.user.has_perm('kfet.is_team'): + transfer_dict['canceled_by__trigramme'] = ( + transfer.canceled_by + and transfer.canceled_by.trigramme + or None) + transfergroup_dict['opes'].append(transfer_dict) + opegroups_list.append(transfergroup_dict) + + opegroups_list.sort(key=lambda group: group['at']) + + return JsonResponse({'opegroups': opegroups_list}) @teamkfet_required def kpsul_articles_data(request):