From 7320a1a4be36fac5cf973cbcb5b3fb65de2feecf Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sun, 26 May 2024 18:08:19 +0200 Subject: [PATCH] render albums column in file table properly --- src/files/tables.py | 30 +++++++++++++++++++++++++++++- src/files/templates/file_list.html | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/files/tables.py b/src/files/tables.py index e4085ed..e77429f 100644 --- a/src/files/tables.py +++ b/src/files/tables.py @@ -1,5 +1,9 @@ """This module defines the table used to show files.""" import django_tables2 as tables +from albums.models import Album +from django.urls import reverse +from django.utils import timezone +from django.utils.safestring import mark_safe from .models import BaseFile @@ -9,10 +13,34 @@ class FileTable(tables.Table): selection = tables.CheckBoxColumn(accessor="pk", orderable=False) uuid = tables.Column(linkify=True) + albums = tables.Column(verbose_name="Albums") + + def render_albums(self, record: BaseFile) -> str: + """Render albums as a list of links.""" + output = "" + for album in Album.objects.filter( + memberships__basefile__pk__contains=record.pk, memberships__period__contains=timezone.now() + ): + output += ( + '' + album.title + "
" + ) + return mark_safe(output) # noqa: S308 class Meta: """Define model, template, fields.""" model = BaseFile template_name = "django_tables2/bootstrap.html" - fields = ("uuid", "albums", "attribution", "uploader", "license", "file_size", "status", "title") + fields = ( + "selection", + "uuid", + "title", + "albums", + "attribution", + "uploader", + "license", + "file_size", + "approved", + "published", + "deleted", + ) diff --git a/src/files/templates/file_list.html b/src/files/templates/file_list.html index 25a823a..8a41094 100644 --- a/src/files/templates/file_list.html +++ b/src/files/templates/file_list.html @@ -9,7 +9,7 @@
-
Filter
+
Filter Files
{% bootstrap_form filter.form %}