aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-05-21 11:53:48 +0200
committerDaniel Schadt <kingdread@gmx.de>2023-05-21 11:53:48 +0200
commitd43bfc29f39ddd37ec93f5c2caa865b01f62a6a2 (patch)
treed3e05ddef3fc94c39815217f8befa238167c7abe
parent74326f67de6d9c3ed9a235d4d31cc863e510d8b1 (diff)
downloadfietsboek-d43bfc29f39ddd37ec93f5c2caa865b01f62a6a2.tar.gz
fietsboek-d43bfc29f39ddd37ec93f5c2caa865b01f62a6a2.tar.bz2
fietsboek-d43bfc29f39ddd37ec93f5c2caa865b01f62a6a2.zip
sort images by their original file name
This is better than the "random" sort we get otherwise, but maybe one day we can allow the user to re-arrange the images and save the sorting in the database. But this is rather low-priority, this way at least the images are shown in the correct order if they are named systematically.
-rw-r--r--fietsboek/views/detail.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py
index f540a11..ec66922 100644
--- a/fietsboek/views/detail.py
+++ b/fietsboek/views/detail.py
@@ -20,6 +20,17 @@ from ..models.track import TrackWithMetadata
LOGGER = logging.getLogger(__name__)
+def _sort_key(image_name: str) -> str:
+ """Returns the "key" by which the image should be sorted.
+
+ :param image_name: Name of the image (on disk).
+ :return: The value that should be used to sort the image.
+ """
+ if "_" not in image_name:
+ return image_name
+ return image_name.split("_", 1)[1]
+
+
@view_config(
route_name="details", renderer="fietsboek:templates/details.jinja2", permission="track.view"
)
@@ -51,9 +62,13 @@ def details(request):
query = select(models.ImageMetadata).filter_by(track=track, image_name=image_name)
image_metadata = request.dbsession.execute(query).scalar_one_or_none()
if image_metadata:
- images.append((img_src, image_metadata.description))
+ images.append((_sort_key(image_name), img_src, image_metadata.description))
else:
- images.append((img_src, ""))
+ images.append((_sort_key(image_name), img_src, ""))
+
+ images.sort(key=lambda element: element[0])
+ # Strip off the sort key again
+ images = [(image[1], image[2]) for image in images]
with_meta = TrackWithMetadata(track, request.data_manager)
return {