diff options
author | Caleb Forbes Davis V <caldavis@gmail.com> | 2011-07-12 20:06:17 -0500 |
---|---|---|
committer | Caleb Forbes Davis V <caldavis@gmail.com> | 2011-07-12 20:06:17 -0500 |
commit | cdf538bd6163a47b4c4a6326c943b6deaf2c495a (patch) | |
tree | 074a0316483ebd3dd34e016a97ac78195e661579 /mediagoblin/util.py | |
parent | 272469daf5eb53f2302ae3948dde4e40eaf12497 (diff) | |
download | mediagoblin-cdf538bd6163a47b4c4a6326c943b6deaf2c495a.tar.lz mediagoblin-cdf538bd6163a47b4c4a6326c943b6deaf2c495a.tar.xz mediagoblin-cdf538bd6163a47b4c4a6326c943b6deaf2c495a.zip |
adds filter function to parse and clean tags field input
- for some reason the tags are showing up in the media edit form
with u'..' and surrounded with []. I don't know why, grr
Diffstat (limited to 'mediagoblin/util.py')
-rw-r--r-- | mediagoblin/util.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/mediagoblin/util.py b/mediagoblin/util.py index ab219df0..7ee0a2d5 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -22,6 +22,7 @@ import sys import re import urllib from math import ceil +from string import strip import copy from babel.localedata import exists @@ -369,8 +370,24 @@ def clean_html(html): return HTML_CLEANER.clean_html(html) -MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape') +TAGS_DELIMITER = ' ' + +def convert_to_tag_list(tag_string): + """ + Filter input from a "tags" field, + Strips trailing, leading, and internal whitespace, and also converts + the user input into an array of tags + """ + if tag_string: + taglist = [] + stripped_tag_string = ' '.join(tag_string.strip().split()) + for tag in stripped_tag_string.split(TAGS_DELIMITER): + if tag.strip(): taglist.append(tag.strip()) + return taglist + + +MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape') def cleaned_markdown_conversion(text): """ |