Simplify JS-Python interface for cancel_ops

This commit is contained in:
Ludovic Stephan 2017-03-24 23:57:27 -03:00
parent 1fcd53d780
commit aa6a50a6e7
2 changed files with 13 additions and 14 deletions

View file

@ -59,11 +59,16 @@ class History {
$(document).on('keydown', function(e) {
if (e.keyCode == 46) {
//DEL key ; we delete the selected operations (if any)
var to_cancel = [];
var to_cancel = {'transfers': [], 'opes': [],};
that._$container.find('.ope.ui-selected').each(function() {
to_cancel.push($(this).parent().attr('id')) ;
var [type, id] = $(this).parent().attr('id').split('-');
if (type === 'transfer')
to_cancel['transfers'].push(id);
else
to_cancel['opes'].push(id);
});
if (to_cancel.length > 0)
if (to_cancel['opes'].length > 0 || to_cancel['transfers'].length > 0)
that.cancel_operations(to_cancel);
}
});
@ -86,13 +91,11 @@ class History {
var focus_next = undefined;
}
var data = { 'operations': to_cancel };
$.ajax({
dataType: "json",
url : Urls['kfet.kpsul.cancel_operations'](),
method : "POST",
data : data,
data : to_cancel,
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '')

View file

@ -1134,14 +1134,10 @@ def kpsul_cancel_operations(request):
# Checking if BAD REQUEST (opes_pk not int or not existing)
try:
# Set pour virer les doublons
opes_post = set(map(lambda s: int(s.split('-')[1]),
filter(lambda s: s.split('-')[0] == 'purchase'
or s.split('-')[0] == 'specialope',
request.POST.getlist('operations[]', []))))
transfers_post = \
set(map(lambda s: int(s.split('-')[1]),
filter(lambda s: s.split('-')[0] == 'transfer',
request.POST.getlist('operations[]', []))))
opes_post = set(map(lambda s: int(s),
request.POST.getlist('opes[]', [])))
transfers_post = set(map(lambda s: int(s),
request.POST.getlist('transfers[]', [])))
except ValueError:
return JsonResponse(data, status=400)