Add api endpoint /tag/tagname/add_synonym.

This commit is contained in:
voussoir 2021-01-05 14:02:08 -08:00
parent fec280bf99
commit dd54eabd93
2 changed files with 31 additions and 11 deletions

View file

@ -52,6 +52,17 @@ def post_tag_add_child(tagname):
response = {'action': 'add_child', 'tagname': f'{parent.name}.{child.name}'} response = {'action': 'add_child', 'tagname': f'{parent.name}.{child.name}'}
return jsonify.make_json_response(response) return jsonify.make_json_response(response)
@site.route('/tag/<tagname>/add_synonym', methods=['POST'])
@decorators.required_fields(['syn_name'], forbid_whitespace=True)
def post_tag_add_synonym(tagname):
syn_name = request.form['syn_name']
master_tag = common.P_tag(tagname, response_type='json')
syn_name = master_tag.add_synonym(syn_name, commit=True)
response = {'action': 'add_synonym', 'synonym': syn_name}
return jsonify.make_json_response(response)
@site.route('/tag/<tagname>/remove_child', methods=['POST']) @site.route('/tag/<tagname>/remove_child', methods=['POST'])
@decorators.required_fields(['child_name'], forbid_whitespace=True) @decorators.required_fields(['child_name'], forbid_whitespace=True)
def post_tag_remove_child(tagname): def post_tag_remove_child(tagname):
@ -61,6 +72,17 @@ def post_tag_remove_child(tagname):
response = {'action': 'remove_child', 'tagname': f'{parent.name}.{child.name}'} response = {'action': 'remove_child', 'tagname': f'{parent.name}.{child.name}'}
return jsonify.make_json_response(response) return jsonify.make_json_response(response)
@site.route('/tag/<tagname>/remove_synonym', methods=['POST'])
@decorators.required_fields(['syn_name'], forbid_whitespace=True)
def post_tag_remove_synonym(tagname):
syn_name = request.form['syn_name']
master_tag = common.P_tag(tagname, response_type='json')
syn_name = master_tag.remove_synonym(syn_name, commit=True)
response = {'action': 'delete_synonym', 'synonym': syn_name}
return jsonify.make_json_response(response)
# Tag listings ##################################################################################### # Tag listings #####################################################################################
@site.route('/all_tags.json') @site.route('/all_tags.json')
@ -159,14 +181,3 @@ def post_tag_delete(tagname):
tag.delete(commit=True) tag.delete(commit=True)
response = {'action': 'delete_tag', 'tagname': tag.name} response = {'action': 'delete_tag', 'tagname': tag.name}
return jsonify.make_json_response(response) return jsonify.make_json_response(response)
@site.route('/tag/<tagname>/remove_synonym', methods=['POST'])
@decorators.required_fields(['syn_name'], forbid_whitespace=True)
def post_tag_remove_synonym(tagname):
syn_name = request.form['syn_name']
master_tag = common.P_tag(tagname, response_type='json')
master_tag.remove_synonym(syn_name, commit=True)
response = {'action': 'delete_synonym', 'synonym': syn_name}
return jsonify.make_json_response(response)

View file

@ -312,6 +312,15 @@ function add_child(tag_name, child_name, callback)
common.post(url, data, callback); common.post(url, data, callback);
} }
api.tags.add_synonym =
function add_synonym(tag_name, syn_name, callback)
{
const url = `/tag/${tag_name}/add_synonym`;
const data = new FormData();
data.append("syn_name", syn_name);
common.post(url, data, callback);
}
api.tags.create = api.tags.create =
function create(name, description, callback) function create(name, description, callback)
{ {