From 7af7c034666d85dd6c89ad8b4593a9646a205d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Tue, 9 Aug 2016 11:06:42 +0200 Subject: [PATCH] get_missing_perms dans perform K-Psul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Car plus performante en requĂȘte BDD --- kfet/views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index 4c5ad69f..842e372a 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -542,11 +542,7 @@ def kpsul_perform_operations(request): data['operations'].append(operation.pk) except PermissionDenied: # Sending BAD_REQUEST with missing perms or url to manage negative - missing_perms = \ - [ Permission.objects.get(codename=codename).name for codename in ( - (perm.split('.'))[1] for perm in - required_perms if not request.user.has_perm(perm) - )] + missing_perms = get_missing_perms(required_perms, request.user) if missing_perms: data['errors'].append({'missing_perms': missing_perms }) if stop_ope: @@ -566,7 +562,10 @@ def kpsul_cancel_operations(request): opes_post = set(map(int, filter(None, request.POST.getlist('operation', [])))) except ValueError: 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_notexisting = [ ope for ope in opes_post if ope not in opes_pk ] if opes_notexisting: