From bc4895e01dd6db8e82f067ba2384614214d2f60a Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 26 Jul 2022 19:01:21 +0200 Subject: fix image upload when uploading tracks Since we changed the logic to support image descriptions, we need to adapt it here as well. Without this fix, images would only be uploaded from the "edit track" view. --- fietsboek/views/upload.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fietsboek/views/upload.py b/fietsboek/views/upload.py index bbd8f68..ea04e3f 100644 --- a/fietsboek/views/upload.py +++ b/fietsboek/views/upload.py @@ -1,6 +1,7 @@ """Upload functionality.""" import datetime import logging +import re from pyramid.httpexceptions import HTTPFound, HTTPBadRequest from pyramid.response import Response @@ -170,10 +171,20 @@ def do_finish_upload(request): request.dbsession.add(track.cache) # Don't forget to add the images - for image in request.params.getall("image[]"): + for param_name, image in request.params.items(): + match = re.match("image\\[(\\d+)\\]$", param_name) + if not match: + continue + # Sent for the multi input if image == b"": continue - request.data_manager.add_image(track.id, image.file, image.filename) + + upload_id = match.group(1) + image_name = request.data_manager.add_image(track.id, image.file, image.filename) + image_meta = models.ImageMetadata(track=track, image_name=image_name) + image_meta.description = request.params.get(f"image-description[{upload_id}]", "") + request.dbsession.add(image_meta) + LOGGER.debug("Uploaded image %s %s", track.id, image_name) request.session.flash(request.localizer.translate(_("flash.upload_success"))) -- cgit v1.2.3