Add endpoints /batch/photos/add_tag and /remove_tag.
This commit is contained in:
parent
13e8bc4a6f
commit
761ae5c30c
1 changed files with 46 additions and 12 deletions
|
@ -68,14 +68,19 @@ def get_thumbnail(photo_id):
|
||||||
# Photo tag operations #############################################################################
|
# Photo tag operations #############################################################################
|
||||||
|
|
||||||
@decorators.catch_etiquette_exception
|
@decorators.catch_etiquette_exception
|
||||||
def post_photo_add_remove_tag_core(photo_id, tagname, add_or_remove):
|
def post_photo_add_remove_tag_core(photo_ids, tagname, add_or_remove):
|
||||||
photo = common.P_photo(photo_id, response_type='json')
|
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]
|
||||||
tag = common.P_tag(tagname, response_type='json')
|
tag = common.P_tag(tagname, response_type='json')
|
||||||
|
|
||||||
if add_or_remove == 'add':
|
for photo in photos:
|
||||||
photo.add_tag(tag)
|
if add_or_remove == 'add':
|
||||||
elif add_or_remove == 'remove':
|
photo.add_tag(tag, commit=False)
|
||||||
photo.remove_tag(tag)
|
elif add_or_remove == 'remove':
|
||||||
|
photo.remove_tag(tag, commit=False)
|
||||||
|
common.P.commit()
|
||||||
|
|
||||||
response = {'tagname': tag.name}
|
response = {'tagname': tag.name}
|
||||||
return jsonify.make_json_response(response)
|
return jsonify.make_json_response(response)
|
||||||
|
@ -86,7 +91,12 @@ def post_photo_add_tag(photo_id):
|
||||||
'''
|
'''
|
||||||
Add a tag to this photo.
|
Add a tag to this photo.
|
||||||
'''
|
'''
|
||||||
return post_photo_add_remove_tag_core(photo_id, request.form['tagname'], 'add')
|
response = post_photo_add_remove_tag_core(
|
||||||
|
photo_ids=photo_id,
|
||||||
|
tagname=request.form['tagname'],
|
||||||
|
add_or_remove='add',
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
@site.route('/photo/<photo_id>/remove_tag', methods=['POST'])
|
@site.route('/photo/<photo_id>/remove_tag', methods=['POST'])
|
||||||
@decorators.required_fields(['tagname'], forbid_whitespace=True)
|
@decorators.required_fields(['tagname'], forbid_whitespace=True)
|
||||||
|
@ -94,7 +104,32 @@ def post_photo_remove_tag(photo_id):
|
||||||
'''
|
'''
|
||||||
Remove a tag from this photo.
|
Remove a tag from this photo.
|
||||||
'''
|
'''
|
||||||
return post_photo_add_remove_tag_core(photo_id, request.form['tagname'], 'remove')
|
response = post_photo_add_remove_tag_core(
|
||||||
|
photo_ids=photo_id,
|
||||||
|
tagname=request.form['tagname'],
|
||||||
|
add_or_remove='remove',
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
@site.route('/batch/photos/add_tag', methods=['POST'])
|
||||||
|
@decorators.required_fields(['photo_ids', 'tagname'], forbid_whitespace=True)
|
||||||
|
def post_batch_photos_add_tag():
|
||||||
|
response = post_photo_add_remove_tag_core(
|
||||||
|
photo_ids=request.form['photo_ids'],
|
||||||
|
tagname=request.form['tagname'],
|
||||||
|
add_or_remove='add',
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
@site.route('/batch/photos/remove_tag', methods=['POST'])
|
||||||
|
@decorators.required_fields(['photo_ids', 'tagname'], forbid_whitespace=True)
|
||||||
|
def post_batch_photos_remove_tag():
|
||||||
|
response = post_photo_add_remove_tag_core(
|
||||||
|
photo_ids=request.form['photo_ids'],
|
||||||
|
tagname=request.form['tagname'],
|
||||||
|
add_or_remove='remove',
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
# Photo metadata operations ########################################################################
|
# Photo metadata operations ########################################################################
|
||||||
|
|
||||||
|
@ -123,13 +158,12 @@ def get_clipboard_page():
|
||||||
return flask.render_template('clipboard.html')
|
return flask.render_template('clipboard.html')
|
||||||
|
|
||||||
@site.route('/batch/photos/photo_card', methods=['POST'])
|
@site.route('/batch/photos/photo_card', methods=['POST'])
|
||||||
|
@decorators.required_fields(['photo_ids'], forbid_whitespace=True)
|
||||||
def post_batch_photos_photo_cards():
|
def post_batch_photos_photo_cards():
|
||||||
photo_ids = request.form.get('photo_ids', None)
|
photo_ids = request.form['photo_ids']
|
||||||
if photo_ids is None:
|
|
||||||
return jsonify.make_json_response({})
|
|
||||||
|
|
||||||
photo_ids = etiquette.helpers.comma_space_split(photo_ids)
|
photo_ids = etiquette.helpers.comma_space_split(photo_ids)
|
||||||
photos = [common.P_photo(photo_id, response_type='html') for photo_id in photo_ids]
|
photos = [common.P_photo(photo_id, response_type='json') for photo_id in photo_ids]
|
||||||
|
|
||||||
# Photo filenames are prevented from having colons, so using it as a split
|
# Photo filenames are prevented from having colons, so using it as a split
|
||||||
# delimiter should be safe.
|
# delimiter should be safe.
|
||||||
|
|
Loading…
Reference in a new issue