From 89205ac24ad858fc20a226c8d176c38b58ceab21 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 29 Apr 2021 13:12:37 -0700 Subject: [PATCH] Add interface for copying tags from other photos. --- .../backend/endpoints/photo_endpoints.py | 12 ++++++++++ frontends/etiquette_flask/static/js/api.js | 9 ++++++++ .../etiquette_flask/templates/photo.html | 22 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py index 9215c5d..db38b51 100644 --- a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py @@ -110,6 +110,18 @@ def post_photo_add_tag(photo_id): ) return response +@site.route('/photo//copy_tags', methods=['POST']) +@decorators.required_fields(['other_photo'], forbid_whitespace=True) +def post_photo_copy_tags(photo_id): + ''' + Copy the tags from another photo. + ''' + photo = common.P_photo(photo_id, response_type='json') + other = common.P_photo(request.form['other_photo'], response_type='json') + photo.copy_tags(other) + common.P.commit('photo copy tags') + return jsonify.make_json_response([tag.jsonify(minimal=True) for tag in photo.get_tags()]) + @site.route('/photo//remove_tag', methods=['POST']) @decorators.required_fields(['tagname'], forbid_whitespace=True) def post_photo_remove_tag(photo_id): diff --git a/frontends/etiquette_flask/static/js/api.js b/frontends/etiquette_flask/static/js/api.js index 600c3e4..302247f 100644 --- a/frontends/etiquette_flask/static/js/api.js +++ b/frontends/etiquette_flask/static/js/api.js @@ -239,6 +239,15 @@ function batch_unset_searchhidden(photo_ids, callback) common.post(url, data, callback); } +api.photos.copy_tags = +function copy_tags(photo_id, other_photo, callback) +{ + const url = `/photo/${photo_id}/copy_tags`; + const data = new FormData(); + data.append("other_photo", other_photo); + common.post(url, data, callback) +} + api.photos.delete = function _delete(photo_id, delete_file, callback) { diff --git a/frontends/etiquette_flask/templates/photo.html b/frontends/etiquette_flask/templates/photo.html index ab53dbf..b2ccbc7 100644 --- a/frontends/etiquette_flask/templates/photo.html +++ b/frontends/etiquette_flask/templates/photo.html @@ -257,6 +257,18 @@ {% if photo.simple_mimetype == "video" %} {% endif %} + + +