From f265346a10ecb69c65c00dbcc65e78bc755c3062 Mon Sep 17 00:00:00 2001 From: Sli Date: Wed, 31 Jul 2024 11:56:38 +0200 Subject: [PATCH] Sort pictures by album in zip file --- core/templates/core/user_pictures.jinja | 3 ++- sas/api.py | 2 ++ sas/schemas.py | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/templates/core/user_pictures.jinja b/core/templates/core/user_pictures.jinja index d0502f4f..b142c681 100644 --- a/core/templates/core/user_pictures.jinja +++ b/core/templates/core/user_pictures.jinja @@ -80,6 +80,7 @@ * @property {string} full_size_url * @property {string} compressed_url * @property {string} thumb_url + * @property {string} album */ document.addEventListener("alpine:init", () => { @@ -104,7 +105,7 @@ const zipWriter = new zip.ZipWriter(await fileHandle.createWritable()); await Promise.all(pictures.map(p => { - const img_name = "IMG_" + p.date.replaceAll(/[:\-]/g, "_") + p.name.slice(p.name.lastIndexOf(".")); + const img_name = p.album + "/IMG_" + p.date.replaceAll(/[:\-]/g, "_") + p.name.slice(p.name.lastIndexOf(".")); return zipWriter.add( img_name, new zip.HttpReader(p.full_size_url), diff --git a/sas/api.py b/sas/api.py index ea4c1c74..807339f3 100644 --- a/sas/api.py +++ b/sas/api.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.db.models import F from ninja import Query from ninja_extra import ControllerBase, api_controller, route from ninja_extra.exceptions import PermissionDenied @@ -47,6 +48,7 @@ class PicturesController(ControllerBase): ) .distinct() .order_by("-date") + .annotate(album=F("parent__name")) ) for picture in pictures: picture.full_size_url = picture.get_download_url() diff --git a/sas/schemas.py b/sas/schemas.py index 14388a2d..b9af0d72 100644 --- a/sas/schemas.py +++ b/sas/schemas.py @@ -23,6 +23,7 @@ class PictureSchema(ModelSchema): full_size_url: str compressed_url: str thumb_url: str + album: str class PictureCreateRelationSchema(Schema):