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
This commit is contained in:
parent
272469daf5
commit
cdf538bd61
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
import wtforms
|
import wtforms
|
||||||
|
|
||||||
|
from mediagoblin.util import convert_to_tag_list
|
||||||
|
|
||||||
|
|
||||||
class EditForm(wtforms.Form):
|
class EditForm(wtforms.Form):
|
||||||
title = wtforms.TextField(
|
title = wtforms.TextField(
|
||||||
@ -25,8 +27,7 @@ class EditForm(wtforms.Form):
|
|||||||
slug = wtforms.TextField(
|
slug = wtforms.TextField(
|
||||||
'Slug')
|
'Slug')
|
||||||
description = wtforms.TextAreaField('Description of this work')
|
description = wtforms.TextAreaField('Description of this work')
|
||||||
tags = wtforms.TextField(
|
tags = wtforms.TextField('Tags', filters=[convert_to_tag_list])
|
||||||
'Tags')
|
|
||||||
|
|
||||||
class EditProfileForm(wtforms.Form):
|
class EditProfileForm(wtforms.Form):
|
||||||
bio = wtforms.TextAreaField('Bio',
|
bio = wtforms.TextAreaField('Bio',
|
||||||
|
@ -19,7 +19,8 @@ from webob import exc
|
|||||||
from string import split
|
from string import split
|
||||||
|
|
||||||
from mediagoblin import messages
|
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 import forms
|
||||||
from mediagoblin.edit.lib import may_edit_media
|
from mediagoblin.edit.lib import may_edit_media
|
||||||
from mediagoblin.decorators import require_active_login, get_user_media_entry
|
from mediagoblin.decorators import require_active_login, get_user_media_entry
|
||||||
@ -37,7 +38,7 @@ def edit_media(request, media):
|
|||||||
title = media['title'],
|
title = media['title'],
|
||||||
slug = media['slug'],
|
slug = media['slug'],
|
||||||
description = media['description'],
|
description = media['description'],
|
||||||
tags = ' '.join(media['tags']))
|
tags = TAGS_DELIMITER.join(media['tags']))
|
||||||
|
|
||||||
if request.method == 'POST' and form.validate():
|
if request.method == 'POST' and form.validate():
|
||||||
# Make sure there isn't already a MediaEntry with such a slug
|
# Make sure there isn't already a MediaEntry with such a slug
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
import wtforms
|
import wtforms
|
||||||
|
|
||||||
|
from mediagoblin.util import convert_to_tag_list
|
||||||
|
|
||||||
|
|
||||||
class SubmitStartForm(wtforms.Form):
|
class SubmitStartForm(wtforms.Form):
|
||||||
title = wtforms.TextField(
|
title = wtforms.TextField(
|
||||||
@ -24,4 +26,4 @@ class SubmitStartForm(wtforms.Form):
|
|||||||
[wtforms.validators.Length(min=0, max=500)])
|
[wtforms.validators.Length(min=0, max=500)])
|
||||||
description = wtforms.TextAreaField('Description of this work')
|
description = wtforms.TextAreaField('Description of this work')
|
||||||
file = wtforms.FileField('File')
|
file = wtforms.FileField('File')
|
||||||
tags = wtforms.TextField('Tags')
|
tags = wtforms.TextField('Tags', filters=[convert_to_tag_list])
|
||||||
|
@ -22,6 +22,7 @@ import sys
|
|||||||
import re
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
from string import strip
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from babel.localedata import exists
|
from babel.localedata import exists
|
||||||
@ -369,8 +370,24 @@ def clean_html(html):
|
|||||||
return HTML_CLEANER.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):
|
def cleaned_markdown_conversion(text):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user