Skip to content

Commit

Permalink
improve people rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Oct 22, 2024
1 parent ef2a8c5 commit acfaabb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions metadata_catalogue/datasets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion metadata_catalogue/datasets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit acfaabb

Please sign in to comment.