get_missing_perms dans perform K-Psul

Car plus performante en requête BDD
This commit is contained in:
Aurélien Delobelle 2016-08-09 11:06:42 +02:00
parent 2c2f82a0f7
commit 7af7c03466

View file

@ -542,11 +542,7 @@ def kpsul_perform_operations(request):
data['operations'].append(operation.pk) data['operations'].append(operation.pk)
except PermissionDenied: except PermissionDenied:
# Sending BAD_REQUEST with missing perms or url to manage negative # Sending BAD_REQUEST with missing perms or url to manage negative
missing_perms = \ missing_perms = get_missing_perms(required_perms, request.user)
[ Permission.objects.get(codename=codename).name for codename in (
(perm.split('.'))[1] for perm in
required_perms if not request.user.has_perm(perm)
)]
if missing_perms: if missing_perms:
data['errors'].append({'missing_perms': missing_perms }) data['errors'].append({'missing_perms': missing_perms })
if stop_ope: if stop_ope:
@ -566,7 +562,10 @@ def kpsul_cancel_operations(request):
opes_post = set(map(int, filter(None, request.POST.getlist('operation', [])))) opes_post = set(map(int, filter(None, request.POST.getlist('operation', []))))
except ValueError: except ValueError:
return JsonResponse(data, status=400) return JsonResponse(data, status=400)
opes_all = Operation.objects.select_related('group', 'group__on_acc', 'group__on_acc__negative').filter(pk__in=opes_post) opes_all = (
Operation.objects
.select_related('group', 'group__on_acc', 'group__on_acc__negative')
.filter(pk__in=opes_post))
opes_pk = [ ope.pk for ope in opes_all ] opes_pk = [ ope.pk for ope in opes_all ]
opes_notexisting = [ ope for ope in opes_post if ope not in opes_pk ] opes_notexisting = [ ope for ope in opes_post if ope not in opes_pk ]
if opes_notexisting: if opes_notexisting: