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'}]) == \
# 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
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
# 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):