diff --git a/frontends/etiquette_flask/etiquette_flask/common.py b/frontends/etiquette_flask/etiquette_flask/common.py index b6aa751..57de776 100644 --- a/frontends/etiquette_flask/etiquette_flask/common.py +++ b/frontends/etiquette_flask/etiquette_flask/common.py @@ -85,6 +85,10 @@ def P_bookmark(bookmarkid): def P_photo(photo_id): return P.get_photo(photo_id) +@P_wrapper +def P_photos(photo_ids): + return P.get_photos_by_id(photo_ids) + @P_wrapper def P_tag(tagname): return P.get_tag(name=tagname) diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/album_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/album_endpoints.py index 69358f0..afbcb46 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/album_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/album_endpoints.py @@ -95,10 +95,8 @@ def post_album_add_photo(album_id): album = common.P_album(album_id) photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) - photos = [common.P_photo(photo_id) for photo_id in photo_ids] - for photo in photos: - album.add_photo(photo, commit=False) - common.P.commit() + photos = list(common.P_photos(photo_ids)) + album.add_photos(photos) return jsonify.make_json_response(response) @site.route('/album//remove_photo', methods=['POST']) @@ -113,10 +111,8 @@ def post_album_remove_photo(album_id): album = common.P_album(album_id) photo_ids = etiquette.helpers.comma_space_split(request.form['photo_id']) - photos = [common.P_photo(photo_id) for photo_id in photo_ids] - for photo in photos: - album.remove_photo(photo, commit=False) - common.P.commit() + photos = list(common.P_photos(photo_ids)) + album.remove_photos(photos) return jsonify.make_json_response(response) # Album tag operations ############################################################################# diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py index 353ceba..6df54a6 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py @@ -73,7 +73,7 @@ def post_photo_add_remove_tag_core(photo_ids, tagname, add_or_remove): if isinstance(photo_ids, str): photo_ids = etiquette.helpers.comma_space_split(photo_ids) - photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] + photos = list(common.P_photos(photo_ids, response_type='json')) tag = common.P_tag(tagname, response_type='json') for photo in photos: @@ -139,7 +139,7 @@ def post_photo_refresh_metadata_core(photo_ids): if isinstance(photo_ids, str): photo_ids = etiquette.helpers.comma_space_split(photo_ids) - photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] + photos = list(common.P_photos(photo_ids, response_type='json')) for photo in photos: common.P.caches['photo'].remove(photo.id) @@ -171,7 +171,7 @@ def post_photo_searchhidden_core(photo_ids, searchhidden): if isinstance(photo_ids, str): photo_ids = etiquette.helpers.comma_space_split(photo_ids) - photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] + photos = list(common.P_photos(photo_ids, response_type='json')) for photo in photos: photo.set_searchhidden(searchhidden, commit=False) @@ -206,7 +206,7 @@ def post_batch_photos_photo_cards(): photo_ids = request.form['photo_ids'] photo_ids = etiquette.helpers.comma_space_split(photo_ids) - photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids] + photos = list(common.P_photos(photo_ids, response_type='json')) # Photo filenames are prevented from having colons, so using it as a split # delimiter should be safe.