From 3be8813a0a0bf7efe287b81f6b0ce4a48dc39f59 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 10 Mar 2017 14:04:50 -0800 Subject: [PATCH] Photo.add_tag returns the added tag; site displays the normalized name instead of user input --- etiquette/objects.py | 8 +++++--- etiquette_site.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 26caeee..2df083d 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -422,8 +422,9 @@ class Photo(ObjectBase): def add_tag(self, tag, *, commit=True): tag = self.photodb.get_tag(tag) - if self.has_tag(tag, check_children=False): - return + existing = self.has_tag(tag, check_children=False) + if existing: + return existing # If the new tag is less specific than one we already have, # keep our current one. @@ -431,7 +432,7 @@ class Photo(ObjectBase): if existing: message = 'Preferring existing {exi:s} over {tag:s}'.format(exi=existing, tag=tag) self.photodb.log.debug(message) - return + return existing # If the new tag is more specific, remove our current one for it. for parent in tag.walk_parents(): @@ -447,6 +448,7 @@ class Photo(ObjectBase): if commit: self.photodb.log.debug('Committing - add photo tag') self.photodb.commit() + return tag def albums(self): ''' diff --git a/etiquette_site.py b/etiquette_site.py index 5fd75d3..d4361c9 100644 --- a/etiquette_site.py +++ b/etiquette_site.py @@ -673,7 +673,7 @@ def post_photo_add_remove_tag_core(photoid, tagname, add_or_remove): elif add_or_remove == 'remove': photo.remove_tag(tag) - response = {'tagname': tagname} + response = {'tagname': tag.name} return jsonify.make_json_response(response) @site.route('/photo//add_tag', methods=['POST'])