diff options
-rw-r--r-- | fietsboek/views/upload.py | 15 |
1 files 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"))) |