aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoic Dachary <loic@dachary.org>2016-01-25 19:08:52 +0700
committerAndrew Browning <ayleph@thisshitistemp.com>2016-02-06 14:33:49 -0500
commit679f729221a1d93d1ca48ff6899a548e9daf8f95 (patch)
tree2b21839040746aa33c51c797792fcc08c85de562
parent05f26e3abcd00576c97c9566b2fe33e5085f0601 (diff)
downloadmediagoblin-679f729221a1d93d1ca48ff6899a548e9daf8f95.tar.lz
mediagoblin-679f729221a1d93d1ca48ff6899a548e9daf8f95.tar.xz
mediagoblin-679f729221a1d93d1ca48ff6899a548e9daf8f95.zip
Fix #5079 - tags unicity is on the slug, not the name
Signed-off-by: Loic Dachary <loic@dachary.org> Signed-off-by: Andrew Browning <ayleph@thisshitistemp.com>
-rw-r--r--mediagoblin/tests/test_tags.py4
-rw-r--r--mediagoblin/tools/text.py12
2 files changed, 10 insertions, 6 deletions
diff --git a/mediagoblin/tests/test_tags.py b/mediagoblin/tests/test_tags.py
index e25cc283..8358b052 100644
--- a/mediagoblin/tests/test_tags.py
+++ b/mediagoblin/tests/test_tags.py
@@ -33,6 +33,10 @@ def test_list_of_dicts_conversion(test_app):
assert text.convert_to_tag_list_of_dicts('echo,echo') == [{'name': u'echo',
'slug': u'echo'}]
+ # When checking for duplicates, use the slug, not the tag
+ assert text.convert_to_tag_list_of_dicts('echo,#echo') == [{'name': u'#echo',
+ 'slug': u'echo'}]
+
# Make sure converting the list of dicts to a string works
assert text.media_tags_as_string([{'name': u'yin', 'slug': u'yin'},
{'name': u'yang', 'slug': u'yang'}]) == \
diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py
index 96df49d2..41b7eaea 100644
--- a/mediagoblin/tools/text.py
+++ b/mediagoblin/tools/text.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import collections
import wtforms
import markdown
from lxml.html.clean import Cleaner
@@ -60,7 +61,7 @@ def convert_to_tag_list_of_dicts(tag_string):
Strips trailing, leading, and internal whitespace, and also converts
the "tags" text into an array of tags
"""
- taglist = []
+ slug_to_name = collections.OrderedDict()
if tag_string:
# Strip out internal, trailing, and leading whitespace
@@ -69,11 +70,10 @@ def convert_to_tag_list_of_dicts(tag_string):
# Split the tag string into a list of tags
for tag in stripped_tag_string.split(','):
tag = tag.strip()
- # Ignore empty or duplicate tags
- if tag and tag not in [t['name'] for t in taglist]:
- taglist.append({'name': tag,
- 'slug': url.slugify(tag)})
- return taglist
+ # Ignore empty tags or duplicate slugs
+ if tag:
+ slug_to_name[url.slugify(tag)] = tag
+ return [{'name': v, 'slug': k} for (k,v) in slug_to_name.iteritems()]
def media_tags_as_string(media_entry_tags):