From acfaabbce92ae50ad77c3e51850061ab1197dc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Tue, 22 Oct 2024 18:41:07 +0200 Subject: [PATCH] improve people rendering --- metadata_catalogue/datasets/tables.py | 8 ++++++++ metadata_catalogue/datasets/views.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/metadata_catalogue/datasets/tables.py b/metadata_catalogue/datasets/tables.py index baac118..8951a1c 100644 --- a/metadata_catalogue/datasets/tables.py +++ b/metadata_catalogue/datasets/tables.py @@ -21,6 +21,14 @@ class Meta: class RolesTable(tables.Table): + person = tables.Column(empty_values=()) + + def render_person(self, value, record): + return f"{record['person__last_name']}, {record['person__first_name']}" + + def render_role(self, value: list[str]): + return ", ".join([str(models.PersonRole.RoleType(v).label) for v in value]) + class Meta: model = models.PersonRole template_name = "django_tables2/bootstrap.html" diff --git a/metadata_catalogue/datasets/views.py b/metadata_catalogue/datasets/views.py index 9a56d99..82ef5a4 100644 --- a/metadata_catalogue/datasets/views.py +++ b/metadata_catalogue/datasets/views.py @@ -5,6 +5,7 @@ from typing import Any from django_tables2 import SingleTableView from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.postgres.aggregates import ArrayAgg def get_dataset_vrt_view(request, dataset_uuid): @@ -54,7 +55,16 @@ def get_context_data(self, **kwargs) -> dict[str, Any]: ctx = super().get_context_data(**kwargs) ctx["people_table"] = tables.RolesTable( - self.object.metadata.people.all(), prefix="people-" + self.object.metadata.people.values( + "person__last_name", "person__first_name" + ) + .annotate( + role=ArrayAgg( + "role", + ) + ) + .order_by("person__last_name", "person__first_name"), + prefix="people-", ) return ctx