Skip to content

Commit

Permalink
use linkify=True to render file detail link
Browse files Browse the repository at this point in the history
  • Loading branch information
tykling committed May 16, 2024
1 parent b288dea commit 1f12756
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/files/tables.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""This module defines the table used to show files."""
import django_tables2 as tables
from django.urls import reverse
from django.utils.html import format_html

from .models import BaseFile

Expand All @@ -10,15 +8,11 @@ class FileTable(tables.Table):
"""Defines the django-tables2 used to show files."""

selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
uuid = tables.Column(linkify=True)

class Meta:
"""Define model, template, fields."""

model = BaseFile
template_name = "django_tables2/bootstrap.html"
fields = ("uuid", "albums", "attribution", "uploader", "license", "file_size", "status", "title")

def render_uuid(self, value: str) -> str:
"""Render column data with 'a' tag and return as formatted html."""
url = reverse("files:detail", kwargs={"pk": value})
return format_html(f"<a href='{url}'>{value}</a>")

0 comments on commit 1f12756

Please sign in to comment.