diff --git a/passbook/admin/templates/administration/policybinding/list.html b/passbook/admin/templates/administration/policy_binding/list.html similarity index 55% rename from passbook/admin/templates/administration/policybinding/list.html rename to passbook/admin/templates/administration/policy_binding/list.html index fc84753ae..6b133599a 100644 --- a/passbook/admin/templates/administration/policybinding/list.html +++ b/passbook/admin/templates/administration/policy_binding/list.html @@ -28,29 +28,50 @@ - - + + + - - {% for binding in object_list %} - - - - - - + + {% for pbm in object_list %} + + + + + + + + {% for binding in pbm.bindings %} + + + + + + + + {% endfor %} {% endfor %}
{% trans 'Enabled' %} {% trans 'Policy' %}{% trans 'Target' %}{% trans 'Enabled' %}{% trans 'Order' %}{% trans 'Timeout' %}
-
{{ binding.enabled }}
-
-
{{ binding.policy }}
-
-
{{ binding.target|verbose_name }}
-
- {% trans 'Edit' %} - {% trans 'Delete' %} -
+ {{ pbm }} + + {{ pbm|fieldtype }} + +
+
{{ binding.policy }}
+ + {{ binding.policy|fieldtype }} + +
+
{{ binding.enabled }}
+
+
{{ binding.order }}
+
+
{{ binding.timeout }}
+
+ {% trans 'Edit' %} + {% trans 'Delete' %} +
diff --git a/passbook/admin/views/policies_bindings.py b/passbook/admin/views/policies_bindings.py index 058f78ef1..f90df5a48 100644 --- a/passbook/admin/views/policies_bindings.py +++ b/passbook/admin/views/policies_bindings.py @@ -4,6 +4,7 @@ from django.contrib.auth.mixins import ( PermissionRequiredMixin as DjangoPermissionRequiredMixin, ) from django.contrib.messages.views import SuccessMessageMixin +from django.db.models import QuerySet from django.urls import reverse_lazy from django.utils.translation import ugettext as _ from django.views.generic import ListView, UpdateView @@ -12,7 +13,7 @@ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from passbook.admin.views.utils import DeleteMessageView from passbook.lib.views import CreateAssignPermView from passbook.policies.forms import PolicyBindingForm -from passbook.policies.models import PolicyBinding +from passbook.policies.models import PolicyBinding, PolicyBindingModel class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView): @@ -22,7 +23,20 @@ class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView): permission_required = "passbook_policies.view_policybinding" paginate_by = 10 ordering = ["order", "target"] - template_name = "administration/policybinding/list.html" + template_name = "administration/policy_binding/list.html" + + def get_queryset(self) -> QuerySet: + # Since `select_subclasses` does not work with a foreign key, we have to do two queries here + # First, get all pbm objects that have bindings attached + objects = ( + PolicyBindingModel.objects.filter(policies__isnull=False) + .select_subclasses() + .select_related() + .order_by("pk") + ) + for pbm in objects: + pbm.bindings = PolicyBinding.objects.filter(target__pk=pbm.pbm_uuid) + return objects class PolicyBindingCreateView( diff --git a/passbook/lib/widgets.py b/passbook/lib/widgets.py index 5d026b488..f2104313b 100644 --- a/passbook/lib/widgets.py +++ b/passbook/lib/widgets.py @@ -1,7 +1,5 @@ """Utility Widgets""" -from functools import partial from itertools import groupby -from operator import attrgetter from django.forms.models import ModelChoiceField, ModelChoiceIterator diff --git a/passbook/static/static/passbook/pf.css b/passbook/static/static/passbook/pf.css index 5f18d0cd6..76398607e 100644 --- a/passbook/static/static/passbook/pf.css +++ b/passbook/static/static/passbook/pf.css @@ -235,3 +235,9 @@ input[data-is-monospace] { .pf-c-alert pre { white-space: pre-wrap; } + +/* Table buttons (Don't wrap, align) */ +.pb-table-action { + white-space: nowrap !important; + padding: var(--pf-c-table--cell--PaddingTop) var(--pf-c-table--cell--PaddingRight) var(--pf-c-table--cell--PaddingBottom) var(--pf-c-table--cell--PaddingLeft) !important; +}