From 9cbd9cf2521a8e745ee7eccdc2854299ca855afd Mon Sep 17 00:00:00 2001 From: Klink Date: Sat, 5 Sep 2026 17:54:19 +0200 Subject: [PATCH 1/9] Change to .join() - "Quadratic time complexity" --- src/utils/templatetags/bma_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/templatetags/bma_utils.py b/src/utils/templatetags/bma_utils.py index 1ddd367..bbbe7a4 100644 --- a/src/utils/templatetags/bma_utils.py +++ b/src/utils/templatetags/bma_utils.py @@ -147,16 +147,16 @@ def media_query(container_width: int | None = None, **kwargs: str) -> str: @register.simple_tag() -def render_source_set(*, image: "Image", mimetype: str, aspect_ratio: Fraction | None = None) -> str: +def render_source_set(*, image: "Image", mimetype: str, aspect_ratio: Fraction | str | None = None) -> str: """Return a source set for an image with all the versions of a given mimetype and AR.""" - output = "" + if aspect_ratio and not isinstance(aspect_ratio, Fraction): + aspect_ratio = Fraction(aspect_ratio) + # if aspect_ratio is None (no custom AR was requested): use the AR of the parent Image ratiokey = aspect_ratio or Fraction(image.aspect_ratio) - versions = image.get_versions(mimetype=mimetype, aspect_ratio=aspect_ratio).get(ratiokey, {}).get(mimetype, {}) - for version in versions.values(): - output += f"{version.imagefile.url} {version.width}w, " - # remove trailing ", " - return output[:-2] + versions = image.get_versions(mimetype=mimetype, aspect_ratio=ratiokey).get(ratiokey, {}).get(mimetype, {}) + + return ", ".join(f"{version.imagefile.url} {version.width}w" for version in versions.values()) #.join() is preferable to +=, search: "quadratic time complexity" @register.simple_tag() From f6e377bcd3ff8f3397b0746688b257f1cb2b222f Mon Sep 17 00:00:00 2001 From: Klink Date: Sat, 5 Sep 2026 17:57:44 +0200 Subject: [PATCH 2/9] Adding pagination --- src/files/templates/file_list_grid.html | 50 +++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/files/templates/file_list_grid.html b/src/files/templates/file_list_grid.html index 7f657e1..afb47f2 100644 --- a/src/files/templates/file_list_grid.html +++ b/src/files/templates/file_list_grid.html @@ -1,5 +1,6 @@ {% extends "file_list.html" %} {% load humanize static %} +{% load django_tables2 %} {% block extra_head %} @@ -7,14 +8,55 @@ {% endblock extra_head %} {% block file_list %} -
+
{% include "includes/file_toolbar.html" %} {% csrf_token %}
From 589170d9c2c44dc830c6886e4f7bdb9b354405e3 Mon Sep 17 00:00:00 2001 From: Klink Date: Sat, 5 Sep 2026 18:19:48 +0200 Subject: [PATCH 3/9] Doing some semantics and a bit of finagling --- src/albums/templates/album_list.html | 17 +++++++---------- .../templates/includes/album_filters.html | 2 +- .../templates/includes/album_toolbar.html | 2 +- src/albums/views.py | 1 + src/files/templates/file_list.html | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/albums/templates/album_list.html b/src/albums/templates/album_list.html index 05fdbbd..9c3f8a1 100644 --- a/src/albums/templates/album_list.html +++ b/src/albums/templates/album_list.html @@ -2,22 +2,19 @@ {% load django_bootstrap5 %} {% load render_table from django_tables2 %} {% block title %}Album list{% endblock title %} - {% block main_content %} -
- +
-
- {% include "includes/album_filters.html" %} -
+ -
+

Albums

{% include "includes/album_list_table.html" %} -
- -
+ + {% endblock main_content %} diff --git a/src/albums/templates/includes/album_filters.html b/src/albums/templates/includes/album_filters.html index 411167c..2fd660d 100644 --- a/src/albums/templates/includes/album_filters.html +++ b/src/albums/templates/includes/album_filters.html @@ -2,7 +2,7 @@ {% load django_bootstrap5 %}
Filter Albums - +

Showing {{ filter.qs.count }} of {{ albums.count }} albums

diff --git a/src/albums/templates/includes/album_toolbar.html b/src/albums/templates/includes/album_toolbar.html index 21500f5..1dc9984 100644 --- a/src/albums/templates/includes/album_toolbar.html +++ b/src/albums/templates/includes/album_toolbar.html @@ -2,7 +2,7 @@