aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fietsboek/views/edit.py15
-rw-r--r--fietsboek/views/upload.py18
2 files changed, 15 insertions, 18 deletions
diff --git a/fietsboek/views/edit.py b/fietsboek/views/edit.py
index 2c46527..946a862 100644
--- a/fietsboek/views/edit.py
+++ b/fietsboek/views/edit.py
@@ -83,13 +83,22 @@ def do_edit(request):
tags = request.params.getall("tag[]")
track.sync_tags(tags)
- _edit_images(request)
+ edit_images(request, request.context)
return HTTPFound(request.route_url('details', track_id=track.id))
-def _edit_images(request):
- track = request.context
+def edit_images(request, track):
+ """Edit the images from the given request.
+
+ This deletes and adds images and image descriptions as needed, based on the
+ image[...] and image-description[...] fields.
+
+ :param request: The request:
+ :type request: pyramid.request.Request
+ :param track: The track to edit.
+ :type track: fietsboek.models.track.Track
+ """
# Delete requested images
for image in request.params.getall("delete-image[]"):
diff --git a/fietsboek/views/upload.py b/fietsboek/views/upload.py
index ea04e3f..ea05c74 100644
--- a/fietsboek/views/upload.py
+++ b/fietsboek/views/upload.py
@@ -1,7 +1,6 @@
"""Upload functionality."""
import datetime
import logging
-import re
from pyramid.httpexceptions import HTTPFound, HTTPBadRequest
from pyramid.response import Response
@@ -12,6 +11,7 @@ from sqlalchemy import select
import gpxpy
+from . import edit
from .. import models, util
from ..models.track import Visibility
@@ -171,20 +171,8 @@ def do_finish_upload(request):
request.dbsession.add(track.cache)
# Don't forget to add the images
- 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
-
- 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)
+ LOGGER.debug("Starting to edit images for the upload")
+ edit.edit_images(request, track)
request.session.flash(request.localizer.translate(_("flash.upload_success")))