From 19f1e28308f592aa8b4df6b5d7cb505ab5dbd642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Wed, 27 Jun 2018 19:37:13 +0000 Subject: [PATCH] Refactor display of rights in users/listright page --- static/css/base.css | 6 + users/templates/users/aff_listright.html | 277 ++++++++++++--------- users/templates/users/index_listright.html | 3 +- users/views.py | 24 +- 4 files changed, 191 insertions(+), 119 deletions(-) diff --git a/static/css/base.css b/static/css/base.css index f6240970..2b44e95c 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -108,3 +108,9 @@ footer a { overflow-y: visible; } +/* Make modal wider on wide screens */ +@media (min-width: 1024px) { + .modal-dialog { + width: 1000px + } +} diff --git a/users/templates/users/aff_listright.html b/users/templates/users/aff_listright.html index 8906b38e..14c9fc44 100644 --- a/users/templates/users/aff_listright.html +++ b/users/templates/users/aff_listright.html @@ -22,118 +22,173 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. {% endcomment %} - - - - - - - - - - - - {% if superuser_right %} - - - - - - - - - - - + + + + +{% endif %} - {% endif %} - {% for listright in listright_list %} - - - - - - - - - - - - {% endfor %} -
DroitGidGroupe/permission critiqueInformationsDetails
SuperuserTrue - - - Donne tous les droits sur Re2o. - -
-
-
-
-
    - {% for user in superuser_right %} -
  • - {{user}} - - - -
  • - {% endfor %} -
-
-
+ +
+
- {{ listright.name }} - {{ listright.gid }}{{ listright.critical }} - - {{ listright.details }} - {% include 'buttons/edit.html' with href='users:edit-listright' id=listright.id %} - {% include 'buttons/history.html' with href='users:history' name='listright' id=listright.id %} -
-
-
-
-
    - {% for perm in listright.permissions.all %} -
  • - {{perm.name}} -
  • - {% endfor %} -
-
-
-
-
-
    - {% for user in listright.user_set.all %} -
  • - {{user}} - - - -
  • - {% endfor %} -
-
-
+{% for right, users in rights.items %} +
+
+
+ {% if users %} + + {{users.count}} + + {% else %} + {{users.count}} + {% endif %} + {% include 'buttons/edit.html' with href='users:edit-listright' id=right.id %} + {% include 'buttons/history.html' with href='users:history' name='listright' id=right.id %} +
+

+ + {{right.name}} ({{ right.gid }}) +

+ {{ right.details }} +
+
+
+

Total: {{ right.permissions.count }} permissions

+
    + {% for perm in right.permissions.all %} +
  • + {{perm.name}} +
  • + {% endfor %} +
+
+
+
+ +{% if users %} +
- - + + + + +{% endif %} +{% endfor %} diff --git a/users/templates/users/index_listright.html b/users/templates/users/index_listright.html index 57165792..3b8b3e60 100644 --- a/users/templates/users/index_listright.html +++ b/users/templates/users/index_listright.html @@ -34,9 +34,8 @@ with this program; if not, write to the Free Software Foundation, Inc., Ajouter un droit ou groupe {% acl_end %} Supprimer un ou plusieurs droits/groupes - {% include "users/aff_listright.html" with listright_list=listright_list %} -


+ {% include "users/aff_listright.html" %} {% endblock %} diff --git a/users/views.py b/users/views.py index fcb44f65..b427f710 100644 --- a/users/views.py +++ b/users/views.py @@ -39,7 +39,7 @@ from django.urls import reverse from django.shortcuts import get_object_or_404, render, redirect from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required -from django.db.models import ProtectedError +from django.db.models import ProtectedError, Count, Max from django.utils import timezone from django.db import transaction from django.http import HttpResponse @@ -806,15 +806,27 @@ def index_shell(request): @can_view_all(ListRight) def index_listright(request): """ Affiche l'ensemble des droits""" - listright_list = ListRight.objects.order_by('unix_name')\ - .prefetch_related('permissions').prefetch_related('user_set') - superuser_right = User.objects.filter(is_superuser=True) + rights = {} + for right in (ListRight.objects + .order_by('name') + .prefetch_related('permissions') + .prefetch_related('user_set') + ): + rights[right] = (right.user_set + .annotate(action_number=Count('revision'), + last_seen=Max('revision__date_created')) + ) + superusers = (User.objects + .filter(is_superuser=True) + .annotate(action_number=Count('revision'), + last_seen=Max('revision__date_created')) + ) return render( request, 'users/index_listright.html', { - 'listright_list': listright_list, - 'superuser_right' : superuser_right, + 'rights': rights, + 'superusers' : superusers, } )