Added Roles table

This commit is contained in:
Elijah 2023-11-30 17:05:31 +01:00 committed by Elahi
parent 5d934469c2
commit 5fcfc86f01
3 changed files with 43 additions and 27 deletions

View File

@ -10,9 +10,10 @@ class ButtonColumn(tables.Column):
"a": { "a": {
"type": "button", "type": "button",
"class": "text-primary", "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 # 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 # any empty values in the data, so we stop it from matching the data
# to any value considered empty # to any value considered empty
@ -28,11 +29,15 @@ class UserTable(tables.Table):
"viewname": "idhub:admin_people", "viewname": "idhub:admin_people",
"args": [tables.A("pk")] "args": [tables.A("pk")]
}, },
orderable=False, orderable=False
) )
membership = tables.Column(empty_values=()) membership = tables.Column(empty_values=())
role = tables.Column(empty_values=()) role = tables.Column(empty_values=())
def render_view_user(self):
return format_html('<i class="bi bi-eye"></i>')
def render_membership(self, record): def render_membership(self, record):
return record.get_memberships() return record.get_memberships()
@ -62,6 +67,28 @@ class UserTable(tables.Table):
class RolesTable(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('<i class="bi bi-pencil-square"></i>')
def render_delete_role(self):
return format_html('<i class="bi bi-trash">')
class Meta: class Meta:
model = Rol model = Rol
template_name = "idhub/custom_table.html" template_name = "idhub/custom_table.html"

View File

@ -33,7 +33,8 @@ from idhub.admin.forms import (
) )
from idhub.admin.tables import ( from idhub.admin.tables import (
DashboardTable, DashboardTable,
UserTable UserTable,
RolesTable
) )
from idhub.models import ( from idhub.models import (
DID, DID,
@ -406,18 +407,26 @@ class PeopleRolDeleteView(PeopleView):
return redirect('idhub:admin_people_edit', user.id) return redirect('idhub:admin_people_edit', user.id)
class RolesView(AccessControl): class RolesView(AccessControl, SingleTableView):
template_name = "idhub/admin/roles.html" template_name = "idhub/admin/roles.html"
subtitle = _('Manage roles') subtitle = _('Manage roles')
table_class = RolesTable
icon = '' icon = ''
model = Rol
def get_context_data(self, **kwargs): 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 = super().get_context_data(**kwargs)
context.update({ context.update({
'roles': Rol.objects, 'roles': Rol.objects,
}) })
return context return context
class RolRegisterView(AccessControl, CreateView): class RolRegisterView(AccessControl, CreateView):
template_name = "idhub/admin/rol_register.html" template_name = "idhub/admin/rol_register.html"
subtitle = _('Add role') subtitle = _('Add role')

View File

@ -1,5 +1,6 @@
{% extends "idhub/base_admin.html" %} {% extends "idhub/base_admin.html" %}
{% load i18n %} {% load i18n %}
{% load render_table from django_tables2 %}
{% block content %} {% block content %}
<h3> <h3>
@ -8,31 +9,10 @@
</h3> </h3>
<div class="row mt-5"> <div class="row mt-5">
<div class="col"> <div class="col">
<div class="table-responsive"> {% render_table table %}
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Role' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{% for rol in roles.all %}
<tr>
<td>{{ rol.name }}</td>
<td>{{ rol.description|default:""}}</td>
<td><a href="{% url 'idhub:admin_rol_edit' rol.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
<td><a class="text-danger" href="{% url 'idhub:admin_rol_del' rol.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="form-actions-no-box"> <div class="form-actions-no-box">
<a class="btn btn-green-admin" href="{% url 'idhub:admin_rol_new' %}">{% translate "Add Role" %} <i class="bi bi-plus"></i></a> <a class="btn btn-green-admin" href="{% url 'idhub:admin_rol_new' %}">{% translate "Add Role" %} <i class="bi bi-plus"></i></a>
</div> </div>
</div> </div>
</div>
</div> </div>
{% endblock %} {% endblock %}