aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-26 19:01:21 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-26 19:01:21 +0200
commitbc4895e01dd6db8e82f067ba2384614214d2f60a (patch)
treee6edafcdca82e85629761023736ae0da8081479c
parentf507cd972b4a839e78af19a1030562fe203d22c4 (diff)
downloadfietsboek-bc4895e01dd6db8e82f067ba2384614214d2f60a.tar.gz
fietsboek-bc4895e01dd6db8e82f067ba2384614214d2f60a.tar.bz2
fietsboek-bc4895e01dd6db8e82f067ba2384614214d2f60a.zip
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.
-rw-r--r--fietsboek/views/upload.py15
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")))