enforces maximum tag length with (in)appropriate messaging
This commit is contained in:
parent
4451219560
commit
cc7ff3c505
@ -63,7 +63,9 @@ def edit_media(request, media):
|
|||||||
media['description']))
|
media['description']))
|
||||||
|
|
||||||
media['slug'] = request.POST['slug']
|
media['slug'] = request.POST['slug']
|
||||||
media['tags'] = convert_to_tag_list(request.POST['tags'])
|
|
||||||
|
# Process the user's folksonomy "tags"
|
||||||
|
media['tags'] = convert_to_tag_list(request)
|
||||||
media.save()
|
media.save()
|
||||||
|
|
||||||
return redirect(request, "mediagoblin.user_pages.media_home",
|
return redirect(request, "mediagoblin.user_pages.media_home",
|
||||||
|
@ -60,7 +60,9 @@ def submit_start(request):
|
|||||||
|
|
||||||
entry['media_type'] = u'image' # heh
|
entry['media_type'] = u'image' # heh
|
||||||
entry['uploader'] = request.user['_id']
|
entry['uploader'] = request.user['_id']
|
||||||
entry['tags'] = convert_to_tag_list(request.POST.get('tags'))
|
|
||||||
|
# Process the user's folksonomy "tags"
|
||||||
|
entry['tags'] = convert_to_tag_list(request)
|
||||||
|
|
||||||
# Save, just so we can get the entry id for the sake of using
|
# Save, just so we can get the entry id for the sake of using
|
||||||
# it to generate the file path
|
# it to generate the file path
|
||||||
|
@ -372,19 +372,39 @@ def clean_html(html):
|
|||||||
|
|
||||||
TAGS_DELIMITER = u' '
|
TAGS_DELIMITER = u' '
|
||||||
TAGS_CASE_SENSITIVE = False
|
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
|
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 = []
|
taglist = []
|
||||||
if tag_string:
|
if tag_string:
|
||||||
|
|
||||||
|
# Strip out internal, trailing, and leading whitespace
|
||||||
stripped_tag_string = u' '.join(tag_string.strip().split())
|
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):
|
for tag in stripped_tag_string.split(TAGS_DELIMITER):
|
||||||
|
|
||||||
|
# Do not permit duplicate tags
|
||||||
if tag.strip() and tag not in taglist:
|
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:
|
if TAGS_CASE_SENSITIVE:
|
||||||
taglist.append(tag.strip())
|
taglist.append(tag.strip())
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user