import wtforms
+from mediagoblin.util import convert_to_tag_list
+
class EditForm(wtforms.Form):
title = wtforms.TextField(
slug = wtforms.TextField(
'Slug')
description = wtforms.TextAreaField('Description of this work')
- tags = wtforms.TextField(
- 'Tags')
+ tags = wtforms.TextField('Tags', filters=[convert_to_tag_list])
class EditProfileForm(wtforms.Form):
bio = wtforms.TextAreaField('Bio',
from string import split
from mediagoblin import messages
-from mediagoblin.util import render_to_response, redirect, clean_html
+from mediagoblin.util import render_to_response, redirect, clean_html, \
+ TAGS_DELIMITER
from mediagoblin.edit import forms
from mediagoblin.edit.lib import may_edit_media
from mediagoblin.decorators import require_active_login, get_user_media_entry
title = media['title'],
slug = media['slug'],
description = media['description'],
- tags = ' '.join(media['tags']))
+ tags = TAGS_DELIMITER.join(media['tags']))
if request.method == 'POST' and form.validate():
# Make sure there isn't already a MediaEntry with such a slug
import wtforms
+from mediagoblin.util import convert_to_tag_list
+
class SubmitStartForm(wtforms.Form):
title = wtforms.TextField(
[wtforms.validators.Length(min=0, max=500)])
description = wtforms.TextAreaField('Description of this work')
file = wtforms.FileField('File')
- tags = wtforms.TextField('Tags')
+ tags = wtforms.TextField('Tags', filters=[convert_to_tag_list])
import re
import urllib
from math import ceil
+from string import strip
import copy
from babel.localedata import exists
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):
"""