@@ -23,61 +45,7 @@
-
diff --git a/src/files/managers.py b/src/files/managers.py
index 6ce36de..cfe2ca6 100644
--- a/src/files/managers.py
+++ b/src/files/managers.py
@@ -32,8 +32,8 @@ def get_queryset(self) -> models.QuerySet["BaseFile"]:
)
.prefetch_related("hits")
.annotate(hitcount=Count("hits", distinct=True))
- .annotate(jobs_finished=Count("jobs", filter=models.Q(jobs__finished=False)))
- .annotate(jobs_unfinished=Count("jobs", filter=models.Q(jobs__finished=True)))
+ .annotate(jobs_finished=Count("jobs", filter=models.Q(jobs__finished=True)))
+ .annotate(jobs_unfinished=Count("jobs", filter=models.Q(jobs__finished=False)))
.prefetch_active_albums_list(recursive=True)
.prefetch_related("thumbnail")
)
diff --git a/src/files/tables.py b/src/files/tables.py
index 0cdab3e..2e653ad 100644
--- a/src/files/tables.py
+++ b/src/files/tables.py
@@ -1,6 +1,7 @@
"""This module defines the table used to show files."""
import django_tables2 as tables
+from django.contrib.humanize.templatetags.humanize import intcomma
from django.urls import reverse
from django.utils.safestring import mark_safe
@@ -11,7 +12,7 @@ class FileTable(tables.Table):
"""Defines the django-tables2 used to show files."""
selection = tables.CheckBoxColumn(accessor="pk", orderable=False)
- uuid = tables.Column(linkify=True)
+ uuid = tables.Column(linkify=True, verbose_name="File UUID")
thumbnail = tables.TemplateColumn(
verbose_name="Thumbnail",
template_name="includes/file_thumbnail.html",
@@ -21,6 +22,7 @@ class FileTable(tables.Table):
uploader = tables.Column(linkify=True)
hitcount = tables.Column(verbose_name="Hits")
jobs = tables.Column(verbose_name="Jobs")
+ file_type = tables.Column(verbose_name="File Type")
def render_albums(self, record: BaseFile) -> str:
"""Render albums as a list of links."""
@@ -43,7 +45,20 @@ def render_tags(self, record: BaseFile) -> str:
def render_jobs(self, record: BaseFile) -> str:
"""Render the jobs column."""
- return f"{record.jobs_finished} / {record.jobs_unfinished}"
+ finished_url = reverse("jobs:job_list") + f"?files={record.uuid}&finished=true"
+ unfinished_url = reverse("jobs:job_list") + f"?files={record.uuid}&finished=false"
+ return mark_safe( # noqa: S308
+ f'{record.jobs_unfinished} / '
+ f'{record.jobs_finished}'
+ )
+
+ def render_file_size(self, value: int) -> str:
+ """Render the file size column."""
+ return f"{intcomma(value)} bytes"
+
+ def render_file_type(self, record: BaseFile) -> str:
+ """Render the filetype column."""
+ return mark_safe(f'') # noqa: S308
class Meta:
"""Define model, template, fields."""
@@ -60,6 +75,7 @@ class Meta:
"uploader",
"license",
"file_size",
+ "file_type",
"tags",
"hitcount",
"jobs",
diff --git a/src/files/templates/file_detail.html b/src/files/templates/file_detail.html
index 3d9c48d..4c711f0 100644
--- a/src/files/templates/file_detail.html
+++ b/src/files/templates/file_detail.html
@@ -8,32 +8,22 @@
-
-
- {% picture file.original img_alt=file.title img_class="img-fluid" sm=12 lg=8 %}
-
-
-
-
-
-
+ {% render_file file.original img_alt=file.title img_loading="lazy" img_class="img-fluid" lg=8 sm=12 %}
UUID | -{{ file.pk }} | -
---|---|
Title | -{{ file.title }} | -
Attribution | -{{ file.attribution }} | -
Source | -- {{ file.source }} - | -
License | -- {{ file.license_name }} - | -
Hits | -- {{ file.hits.count }} - | -
Description | -{{ file.description|default:"N/A" }} | -
{{ file.filetype|capfirst }} Tags Details | -- {% for tag in file.tags.all %} - {{ tag }} - {% empty %} - N/A - {% endfor %} - | -
-
+
-
-
- {{ file.filetype|capfirst }} {{ file.title }}
-
- {% picture file.original img_alt=file.title img_loading="lazy" img_class="img-fluid" lg=9 sm=12 %}
+
+
+
+ {{ file.filetype|capfirst }} {{ file.title }}
+
+ {% render_file file.original img_alt=file.title img_loading="lazy" img_class="img-fluid" lg=9 sm=12 %}
+
+
-
-
-
-
-
-
-
-
-
diff --git a/src/files/templates/includes/file_thumbnail.html b/src/files/templates/includes/file_thumbnail.html
index 56383d3..7592fe2 100644
--- a/src/files/templates/includes/file_thumbnail.html
+++ b/src/files/templates/includes/file_thumbnail.html
@@ -1,3 +1,5 @@
{% if record.thumbnail %}
-{% thumbnail record.thumbnail.source width=width|default:50 ratio=ratio|default:"" %}
+{% thumbnail record.thumbnail.source filetype=record.filetype width=width|default:50 ratio=ratio|default:"" %}
+{% else %}
+
{% endif %}
diff --git a/src/files/templates/includes/render_audio.html b/src/files/templates/includes/render_audio.html
new file mode 100644
index 0000000..ea06d27
--- /dev/null
+++ b/src/files/templates/includes/render_audio.html
@@ -0,0 +1,4 @@
+
diff --git a/src/files/templates/includes/render_document.html b/src/files/templates/includes/render_document.html
new file mode 100644
index 0000000..1ea1366
--- /dev/null
+++ b/src/files/templates/includes/render_document.html
@@ -0,0 +1,3 @@
+
+
+
diff --git a/src/files/templates/includes/render_video.html b/src/files/templates/includes/render_video.html
new file mode 100644
index 0000000..81f84c4
--- /dev/null
+++ b/src/files/templates/includes/render_video.html
@@ -0,0 +1,4 @@
+
diff --git a/src/files/tests.py b/src/files/tests.py
index fba4b0c..5fdbe47 100644
--- a/src/files/tests.py
+++ b/src/files/tests.py
@@ -1123,7 +1123,7 @@ def test_file_detail_view(self) -> None:
self.client.login(username="creator2", password="secret")
response = self.client.get(reverse("files:file_detail", kwargs={"file_uuid": self.files[0]}))
content = response.content.decode()
- assert "