diff options
author | Caleb Forbes Davis V <caldavis@gmail.com> | 2011-07-12 23:58:25 -0500 |
---|---|---|
committer | Caleb Forbes Davis V <caldavis@gmail.com> | 2011-07-13 00:03:49 -0500 |
commit | cc7ff3c50513ae169abab196f32de97af30e6744 (patch) | |
tree | 4d5a707f97b5412c026e2438d52b240c3dfd40d5 /mediagoblin/util.py | |
parent | 4451219560a4d991a8c4d04e9dffa99fb092bd5b (diff) | |
download | mediagoblin-cc7ff3c50513ae169abab196f32de97af30e6744.tar.lz mediagoblin-cc7ff3c50513ae169abab196f32de97af30e6744.tar.xz mediagoblin-cc7ff3c50513ae169abab196f32de97af30e6744.zip |
enforces maximum tag length with (in)appropriate messaging
Diffstat (limited to 'mediagoblin/util.py')
-rw-r--r-- | mediagoblin/util.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 951bdd51..44e64258 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -372,19 +372,39 @@ def clean_html(html): TAGS_DELIMITER = u' ' TAGS_CASE_SENSITIVE = False +TAGS_MAX_LENGTH = 50 -def convert_to_tag_list(tag_string): +def convert_to_tag_list(request): """ - Filter input from a "tags" field, + Filter input from any "tags" field in the session, Strips trailing, leading, and internal whitespace, and also converts - the user input into an array of tags + the "tags" text into an array of tags """ + tag_string = request.POST.get('tags') taglist = [] if tag_string: + + # Strip out internal, trailing, and leading whitespace stripped_tag_string = u' '.join(tag_string.strip().split()) + + # Split the tag string into a list of tags for tag in stripped_tag_string.split(TAGS_DELIMITER): + + # Do not permit duplicate tags if tag.strip() and tag not in taglist: + + # Enforce maximum tag length + if len(tag) > TAGS_MAX_LENGTH: + tag = tag[:TAGS_MAX_LENGTH] + u'...' + messages.add_message( + request, messages.WARNING, \ + u'Tag truncated to ' + unicode(TAGS_MAX_LENGTH) + \ + u' characters.') + messages.add_message( + request, messages.INFO, \ + u'Why the long tag? Seriously.') + if TAGS_CASE_SENSITIVE: taglist.append(tag.strip()) else: |