aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 {