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": {
"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('<i class="bi bi-eye"></i>')
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('<i class="bi bi-pencil-square"></i>')
def render_delete_role(self):
return format_html('<i class="bi bi-trash">')
class Meta:
model = Rol
template_name = "idhub/custom_table.html"

View File

@ -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')

View File

@ -1,5 +1,6 @@
{% extends "idhub/base_admin.html" %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block content %}
<h3>
@ -8,31 +9,10 @@
</h3>
<div class="row mt-5">
<div class="col">
<div class="table-responsive">
<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>
{% render_table table %}
<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>
</div>
</div>
</div>
</div>
{% endblock %}