2023-12-09 16:52:53 +00:00
|
|
|
from django.utils.html import format_html
|
2023-12-07 17:43:38 +00:00
|
|
|
import django_tables2 as tables
|
2023-12-09 16:52:53 +00:00
|
|
|
from idhub.models import Event, Membership, UserRol, DID, VerificableCredential
|
2024-03-20 12:02:50 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-12-09 16:52:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ButtonColumn(tables.Column):
|
|
|
|
attrs = {
|
|
|
|
"a": {
|
|
|
|
"type": "button",
|
|
|
|
"class": "text-primary",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# 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
|
|
|
|
empty_values = ()
|
2023-12-07 17:43:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DashboardTable(tables.Table):
|
2024-03-20 12:02:50 +00:00
|
|
|
type = tables.Column(verbose_name=_("Event"))
|
|
|
|
message = tables.Column(verbose_name=_("Description"))
|
|
|
|
created = tables.Column(verbose_name=_("Date"))
|
2023-12-07 17:43:38 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Event
|
|
|
|
template_name = "idhub/custom_table.html"
|
|
|
|
fields = ("type", "message", "created")
|
2024-02-18 20:47:41 +00:00
|
|
|
empty_text="No events available"
|
2023-12-09 16:52:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PersonalInfoTable(tables.Table):
|
2024-03-20 12:02:50 +00:00
|
|
|
type = tables.Column(verbose_name=_("Membership"))
|
2023-12-09 16:52:53 +00:00
|
|
|
credential = ButtonColumn(
|
2024-03-20 12:02:50 +00:00
|
|
|
verbose_name=_("Credential"),
|
2023-12-09 16:52:53 +00:00
|
|
|
# TODO: See where this should actually link
|
|
|
|
linkify="idhub:user_credentials",
|
|
|
|
orderable=False
|
|
|
|
)
|
|
|
|
|
|
|
|
def render_credential(self):
|
|
|
|
return format_html('<i class="bi bi-eye"></i>')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Membership
|
|
|
|
template_name = "idhub/custom_table.html"
|
|
|
|
fields = ("type", "start_date", "end_date", "credential")
|
|
|
|
|
|
|
|
|
|
|
|
class RolesTable(tables.Table):
|
2024-03-20 12:02:50 +00:00
|
|
|
name = tables.Column(verbose_name=_("Role"), empty_values=())
|
|
|
|
description = tables.Column(verbose_name=_("Description"), empty_values=())
|
|
|
|
service = tables.Column(verbose_name=_("Service"))
|
2023-12-09 16:52:53 +00:00
|
|
|
|
|
|
|
def render_name(self, record):
|
|
|
|
return record.service.get_roles()
|
|
|
|
|
|
|
|
def render_description(self, record):
|
|
|
|
return record.service.description
|
|
|
|
|
|
|
|
def render_service(self, record):
|
|
|
|
return record.service.domain
|
|
|
|
|
|
|
|
def order_name(self, queryset, is_descending):
|
|
|
|
queryset = queryset.order_by(
|
|
|
|
("-" if is_descending else "") + "service__rol__name"
|
|
|
|
)
|
|
|
|
|
|
|
|
return (queryset, True)
|
|
|
|
|
|
|
|
def order_description(self, queryset, is_descending):
|
|
|
|
queryset = queryset.order_by(
|
2024-01-04 18:58:28 +00:00
|
|
|
("-" if is_descending else "") + "service__description"
|
|
|
|
)
|
|
|
|
|
|
|
|
return (queryset, True)
|
|
|
|
|
|
|
|
def order_service(self, queryset, is_descending):
|
|
|
|
queryset = queryset.order_by(
|
|
|
|
("-" if is_descending else "") + "service__domain"
|
2023-12-09 16:52:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return (queryset, True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = UserRol
|
|
|
|
template_name = "idhub/custom_table.html"
|
|
|
|
fields = ("name", "description", "service")
|
|
|
|
|
|
|
|
|
|
|
|
class DIDTable(tables.Table):
|
2024-03-20 12:02:50 +00:00
|
|
|
created_at = tables.Column(verbose_name=_("Date"))
|
2023-12-09 16:52:53 +00:00
|
|
|
did = tables.Column(verbose_name="ID")
|
|
|
|
edit = ButtonColumn(
|
2024-03-20 12:02:50 +00:00
|
|
|
verbose_name=_("Edit"),
|
2023-12-09 16:52:53 +00:00
|
|
|
linkify={
|
|
|
|
"viewname": "idhub:user_dids_edit",
|
|
|
|
"args": [tables.A("pk")]
|
|
|
|
},
|
|
|
|
orderable=False
|
|
|
|
)
|
|
|
|
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>"""
|
2024-03-20 12:02:50 +00:00
|
|
|
delete = tables.TemplateColumn(
|
|
|
|
verbose_name=_("Delete"),
|
|
|
|
template_code=delete_template_code,
|
|
|
|
orderable=False
|
|
|
|
)
|
2023-12-09 16:52:53 +00:00
|
|
|
|
|
|
|
def render_edit(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", "delete")
|
|
|
|
|
|
|
|
|
|
|
|
class CredentialsTable(tables.Table):
|
2024-03-20 12:02:50 +00:00
|
|
|
description = tables.Column(verbose_name=_("Details"), empty_values=())
|
2024-02-02 09:12:11 +00:00
|
|
|
view_credential = ButtonColumn(
|
2024-03-20 12:02:50 +00:00
|
|
|
verbose_name=_("View"),
|
2024-02-02 09:12:11 +00:00
|
|
|
linkify={
|
|
|
|
"viewname": "idhub:user_credential",
|
|
|
|
"args": [tables.A("pk")]
|
|
|
|
},
|
|
|
|
orderable=False
|
|
|
|
)
|
2023-12-09 16:52:53 +00:00
|
|
|
|
|
|
|
def render_description(self, record):
|
2023-12-15 18:28:55 +00:00
|
|
|
return record.get_description()
|
2023-12-09 16:52:53 +00:00
|
|
|
|
|
|
|
def render_status(self, record):
|
|
|
|
return record.get_status()
|
|
|
|
|
2023-12-15 18:28:55 +00:00
|
|
|
def order_description(self, queryset, is_descending):
|
|
|
|
queryset = queryset.order_by(
|
|
|
|
("-" if is_descending else "") + "schema__template_description"
|
|
|
|
)
|
|
|
|
|
|
|
|
return (queryset, True)
|
|
|
|
|
2024-02-02 09:12:11 +00:00
|
|
|
def render_view_credential(self):
|
|
|
|
return format_html('<i class="bi bi-eye"></i>')
|
|
|
|
|
2023-12-09 16:52:53 +00:00
|
|
|
class Meta:
|
|
|
|
model = VerificableCredential
|
|
|
|
template_name = "idhub/custom_table.html"
|
|
|
|
fields = ("type", "description", "issued_on", "status")
|