From fb5780aa54b27539e9ccec7d97f378168a12838d Mon Sep 17 00:00:00 2001
From: Loic Dachary <loic@dachary.org>
Date: Mon, 25 Jan 2016 19:08:52 +0700
Subject: [PATCH] Fix #5079 - tags unicity is on the slug, not the name
Signed-off-by: Loic Dachary <loic@dachary.org>
---
mediagoblin/tests/test_tags.py | 4 ++++
mediagoblin/tools/text.py | 12 ++++++------
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/mediagoblin/tests/test_tags.py b/mediagoblin/tests/test_tags.py
index e25cc28..8358b05 100644
|
a
|
b
|
def test_list_of_dicts_conversion(test_app):
|
| 33 | 33 | assert text.convert_to_tag_list_of_dicts('echo,echo') == [{'name': u'echo', |
| 34 | 34 | 'slug': u'echo'}] |
| 35 | 35 | |
| | 36 | # When checking for duplicates, use the slug, not the tag |
| | 37 | assert text.convert_to_tag_list_of_dicts('echo,#echo') == [{'name': u'#echo', |
| | 38 | 'slug': u'echo'}] |
| | 39 | |
| 36 | 40 | # Make sure converting the list of dicts to a string works |
| 37 | 41 | assert text.media_tags_as_string([{'name': u'yin', 'slug': u'yin'}, |
| 38 | 42 | {'name': u'yang', 'slug': u'yang'}]) == \ |
diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py
index 96df49d..41b7eae 100644
|
a
|
b
|
|
| 14 | 14 | # You should have received a copy of the GNU Affero General Public License |
| 15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | 16 | |
| | 17 | import collections |
| 17 | 18 | import wtforms |
| 18 | 19 | import markdown |
| 19 | 20 | from lxml.html.clean import Cleaner |
| … |
… |
def convert_to_tag_list_of_dicts(tag_string):
|
| 60 | 61 | Strips trailing, leading, and internal whitespace, and also converts |
| 61 | 62 | the "tags" text into an array of tags |
| 62 | 63 | """ |
| 63 | | taglist = [] |
| | 64 | slug_to_name = collections.OrderedDict() |
| 64 | 65 | if tag_string: |
| 65 | 66 | |
| 66 | 67 | # Strip out internal, trailing, and leading whitespace |
| … |
… |
def convert_to_tag_list_of_dicts(tag_string):
|
| 69 | 70 | # Split the tag string into a list of tags |
| 70 | 71 | for tag in stripped_tag_string.split(','): |
| 71 | 72 | tag = tag.strip() |
| 72 | | # Ignore empty or duplicate tags |
| 73 | | if tag and tag not in [t['name'] for t in taglist]: |
| 74 | | taglist.append({'name': tag, |
| 75 | | 'slug': url.slugify(tag)}) |
| 76 | | return taglist |
| | 73 | # Ignore empty tags or duplicate slugs |
| | 74 | if tag: |
| | 75 | slug_to_name[url.slugify(tag)] = tag |
| | 76 | return [{'name': v, 'slug': k} for (k,v) in slug_to_name.iteritems()] |
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | def media_tags_as_string(media_entry_tags): |