Added DID and Services tables

This commit is contained in:
Elijah 2023-12-01 12:08:22 +01:00 committed by Elahi
parent fa3eeec327
commit b143e5749c
5 changed files with 131 additions and 35 deletions

View File

@ -1,7 +1,7 @@
import django_tables2 as tables
from django.utils.html import format_html
from idhub.models import Rol, Event
from idhub.models import Rol, Event, Service, VerificableCredential, DID
from idhub_auth.models import User
@ -95,8 +95,107 @@ class RolesTable(tables.Table):
fields = ("name", "description")
class ServicesTable(tables.Table):
domain = tables.Column(verbose_name="Service")
role = tables.Column(empty_values=())
edit_service = ButtonColumn(
linkify={
"viewname": "idhub:admin_service_edit",
"args": [tables.A("pk")]
},
orderable=False
)
delete_service = ButtonColumn(
linkify={
"viewname": "idhub:admin_service_del",
"args": [tables.A("pk")]
},
orderable=False
)
def render_role(self, record):
return record.get_roles()
def render_edit_service(self):
return format_html('<i class="bi bi-pencil-square"></i>')
def render_delete_service(self):
return format_html('<i class="bi bi-trash">')
def order_role(self, queryset, is_descending):
queryset = queryset.order_by(
("-" if is_descending else "") + "rol"
)
return (queryset, True)
class Meta:
model = Service
template_name = "idhub/custom_table.html"
fields = ("domain", "description", "role",
"edit_service", "delete_service")
class DashboardTable(tables.Table):
class Meta:
model = Event
template_name = "idhub/custom_table.html"
fields = ("type", "message", "created")
class CredentialTable(tables.Table):
type = tables.Column(empty_values=())
details = tables.Column(empty_values=())
issued_on = tables.Column(verbose_name="Issued")
view_credential = ButtonColumn(
linkify={
"viewname": "idhub:admin_credential",
"args": [tables.A("pk")]
},
orderable=False
)
def render_type(self, record):
return record.type()
def render_details(self, record):
return record.description()
def render_view_credential(self):
return format_html('<i class="bi bi-eye"></i>')
class Meta:
model = VerificableCredential
template_name = "idhub/custom_table.html"
fields = ("type", "details", "issued_on", "status", "user")
class DIDTable(tables.Table):
created_at = tables.Column(verbose_name="Date")
did = tables.Column(verbose_name="ID")
edit_did = ButtonColumn(
linkify={
"viewname": "idhub:admin_dids_edit",
"args": [tables.A("pk")]
},
orderable=False,
verbose_name="Edit DID"
)
delete_template_code = """<a class="text-danger"
href="javascript:void()"
data-bs-toggle="modal"
data-bs-target="#confirm-delete-{{ record.id }}"
title="Remove"
><i class="bi bi-trash"></i></a>"""
delete_did = tables.TemplateColumn(template_code=delete_template_code,
orderable=False,
verbose_name="Delete DID")
def render_edit_did(self):
return format_html('<i class="bi bi-pencil-square"></i>')
class Meta:
model = DID
template_name = "idhub/custom_table.html"
fields = ("created_at", "label", "did", "edit_did", "delete_did")

View File

@ -34,7 +34,10 @@ from idhub.admin.forms import (
from idhub.admin.tables import (
DashboardTable,
UserTable,
RolesTable
RolesTable,
ServicesTable,
CredentialTable,
DIDTable
)
from idhub.models import (
DID,
@ -473,17 +476,20 @@ class RolDeleteView(AccessControl):
return redirect('idhub:admin_roles')
class ServicesView(AccessControl):
class ServicesView(AccessControl, SingleTableView):
template_name = "idhub/admin/services.html"
table_class = ServicesTable
subtitle = _('Manage services')
icon = ''
model = Service
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'services': Service.objects,
})
return context
queryset = kwargs.pop('object_list', None)
if queryset is None:
self.object_list = self.model.objects.all()
return super().get_context_data(**kwargs)
class ServiceRegisterView(AccessControl, CreateView):
template_name = "idhub/admin/service_register.html"
@ -546,10 +552,12 @@ class ServiceDeleteView(AccessControl):
return redirect('idhub:admin_services')
class CredentialsView(Credentials):
class CredentialsView(Credentials, SingleTableView):
template_name = "idhub/admin/credentials.html"
table_class = CredentialTable
subtitle = _('View credentials')
icon = ''
model = VerificableCredential
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -632,19 +640,26 @@ class DeleteCredentialsView(Credentials):
return redirect(self.success_url)
class DidsView(Credentials):
class DidsView(Credentials, SingleTableView):
template_name = "idhub/admin/dids.html"
table_class = DIDTable
subtitle = _('Manage identities (DID)')
icon = 'bi bi-patch-check-fill'
wallet = True
model = DID
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({
'dids': DID.objects.filter(user=self.request.user),
})
return context
class DidRegisterView(Credentials, CreateView):
template_name = "idhub/admin/did_register.html"
subtitle = _('Add a new organizational identity (DID)')
@ -900,4 +915,3 @@ class ImportAddView(ImportExport, FormView):
else:
messages.error(self.request, _("Error importing the file!"))
return super().form_valid(form)

View File

@ -1,5 +1,6 @@
{% extends "idhub/base_admin.html" %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block content %}
<h3>

View File

@ -1,5 +1,6 @@
{% extends "idhub/base_admin.html" %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block content %}
<h3>
@ -8,6 +9,8 @@
</h3>
<div class="row mt-5">
<div class="col">
{% render_table table %}
{% comment %}
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
@ -31,6 +34,7 @@
{% endfor %}
</tbody>
</table>
{% endcomment %}
<div class="form-actions-no-box">
<a class="btn btn-green-admin" href="{% url 'idhub:admin_dids_new' %}">{% translate "Add identity" %} <i class="bi bi-plus"></i></a>
</div>

View File

@ -1,5 +1,6 @@
{% extends "idhub/base_admin.html" %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block content %}
<h3>
@ -8,33 +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 'Service' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Description' %}</button></th>
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Role' %}</button></th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{% for service in services.all %}
<tr>
<td>{{ service.domain }}</td>
<td>{{ service.description }}</td>
<td>{{ service.get_roles }}</td>
<td><a href="{% url 'idhub:admin_service_edit' service.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
<td><a class="text-danger" href="{% url 'idhub:admin_service_del' service.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_service_new' %}">{% translate "Add service" %} <i class="bi bi-plus"></i></a>
</div>
</div>
</div>
</div>
{% endblock %}