From f99a079b71fbfcd8b710e6c746bada1e10879bbd Mon Sep 17 00:00:00 2001 From: Martin Quarda Date: Mon, 7 Oct 2024 05:58:19 +0200 Subject: [PATCH] new photos directories --- alkatorapi/views.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/alkatorapi/views.py b/alkatorapi/views.py index edce8e2..b2093d4 100644 --- a/alkatorapi/views.py +++ b/alkatorapi/views.py @@ -192,17 +192,18 @@ def results(request): def photos(request): - files = glob.glob("photos/*.jpg") - rtn = [] - random.shuffle(files) - for file in files: - img = PIL.Image.open(file) - rtn.append({ - 'original': '/' + file.replace(".jpg", ".webp"), - 'thumbnail': '/' + file.replace('photos/', 'photos/thumbnail/').replace(".jpg", ".webp"), - 'original_width': img.width, - 'original_height': img.height, - }) + for (i, name) in ALKATOR_CLASSES: + files = glob.glob(f"photos/{i}/*.jpg") + rtn = [] + random.shuffle(files) + for file in files: + img = PIL.Image.open(file) + rtn.append({ + 'original': '/' + file.replace(".jpg", ".webp"), + 'thumbnail': '/' + file.replace('photos/', 'photos/thumbnail/').replace(".jpg", ".webp"), + 'original_width': img.width, + 'original_height': img.height, + }) return HttpResponse(json.dumps(rtn), content_type='application/json')