From 5fcfc86f01f4b153df64979a08f438533b2f0386 Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 30 Nov 2023 17:05:31 +0100 Subject: [PATCH] Added Roles table --- idhub/admin/tables.py | 33 +++++++++++++++++++++++--- idhub/admin/views.py | 13 ++++++++-- idhub/templates/idhub/admin/roles.html | 24 ++----------------- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 252f149..f19d450 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -10,9 +10,10 @@ class ButtonColumn(tables.Column): "a": { "type": "button", "class": "text-primary", - "title": "'View'", } } + # it makes no sense to order a column of buttons + orderable = False # django_tables will only call the render function if it doesn't find # any empty values in the data, so we stop it from matching the data # to any value considered empty @@ -28,11 +29,15 @@ class UserTable(tables.Table): "viewname": "idhub:admin_people", "args": [tables.A("pk")] }, - orderable=False, - ) + orderable=False + ) + membership = tables.Column(empty_values=()) role = tables.Column(empty_values=()) + def render_view_user(self): + return format_html('') + def render_membership(self, record): return record.get_memberships() @@ -62,6 +67,28 @@ class UserTable(tables.Table): class RolesTable(tables.Table): + view_role = ButtonColumn( + linkify={ + "viewname": "idhub:admin_rol_edit", + "args": [tables.A("pk")] + }, + orderable=False + ) + + delete_role = ButtonColumn( + linkify={ + "viewname": "idhub:admin_rol_del", + "args": [tables.A("pk")] + }, + orderable=False + ) + + def render_view_role(self): + return format_html('') + + def render_delete_role(self): + return format_html('') + class Meta: model = Rol template_name = "idhub/custom_table.html" diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 6ea5acd..93e93f8 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -33,7 +33,8 @@ from idhub.admin.forms import ( ) from idhub.admin.tables import ( DashboardTable, - UserTable + UserTable, + RolesTable ) from idhub.models import ( DID, @@ -406,18 +407,26 @@ class PeopleRolDeleteView(PeopleView): return redirect('idhub:admin_people_edit', user.id) -class RolesView(AccessControl): +class RolesView(AccessControl, SingleTableView): template_name = "idhub/admin/roles.html" subtitle = _('Manage roles') + table_class = RolesTable icon = '' + model = Rol def get_context_data(self, **kwargs): + queryset = kwargs.pop('object_list', None) + if queryset is None: + self.object_list = self.model.objects.all() + context = super().get_context_data(**kwargs) context.update({ 'roles': Rol.objects, }) + return context + class RolRegisterView(AccessControl, CreateView): template_name = "idhub/admin/rol_register.html" subtitle = _('Add role') diff --git a/idhub/templates/idhub/admin/roles.html b/idhub/templates/idhub/admin/roles.html index d3d6593..0bc90aa 100644 --- a/idhub/templates/idhub/admin/roles.html +++ b/idhub/templates/idhub/admin/roles.html @@ -1,5 +1,6 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} +{% load render_table from django_tables2 %} {% block content %}

@@ -8,31 +9,10 @@

-
- - - - - - - - - - - {% for rol in roles.all %} - - - - - - - {% endfor %} - -
{{ rol.name }}{{ rol.description|default:""}}
+ {% render_table table %} -
{% endblock %}