uses standard functions instead of form filters and fixes taglist default
- seems simpler to use the same tag field processing procedures on media submit and edit, so now processing with a regular function instead of a form filter. Filters run on form load and post by default. - moved tags to sidebar - taglist defaults to [] instead of None - adds case sensitivity toggle
This commit is contained in:
parent
93e3468a2a
commit
6f2e4585cc
@ -17,8 +17,6 @@
|
||||
|
||||
import wtforms
|
||||
|
||||
from mediagoblin.util import convert_to_tag_list
|
||||
|
||||
|
||||
class EditForm(wtforms.Form):
|
||||
title = wtforms.TextField(
|
||||
|
@ -19,8 +19,9 @@ from webob import exc
|
||||
from string import split
|
||||
|
||||
from mediagoblin import messages
|
||||
from mediagoblin.util import render_to_response, redirect, clean_html, \
|
||||
TAGS_DELIMITER
|
||||
from mediagoblin.util import (
|
||||
render_to_response, redirect, clean_html, TAGS_DELIMITER, \
|
||||
convert_to_tag_list)
|
||||
from mediagoblin.edit import forms
|
||||
from mediagoblin.edit.lib import may_edit_media
|
||||
from mediagoblin.decorators import require_active_login, get_user_media_entry
|
||||
@ -62,7 +63,7 @@ def edit_media(request, media):
|
||||
media['description']))
|
||||
|
||||
media['slug'] = request.POST['slug']
|
||||
media['tags'] = request.POST['tags'].split(TAGS_DELIMITER)
|
||||
media['tags'] = convert_to_tag_list(request.POST['tags'])
|
||||
media.save()
|
||||
|
||||
return redirect(request, "mediagoblin.user_pages.media_home",
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
import wtforms
|
||||
|
||||
from mediagoblin.util import convert_to_tag_list
|
||||
|
||||
|
||||
class SubmitStartForm(wtforms.Form):
|
||||
title = wtforms.TextField(
|
||||
@ -26,4 +24,4 @@ class SubmitStartForm(wtforms.Form):
|
||||
[wtforms.validators.Length(min=0, max=500)])
|
||||
description = wtforms.TextAreaField('Description of this work')
|
||||
file = wtforms.FileField('File')
|
||||
tags = wtforms.TextField('Tags', filters=[convert_to_tag_list])
|
||||
tags = wtforms.TextField('Tags')
|
||||
|
@ -21,7 +21,8 @@ from string import split
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from mediagoblin.util import (
|
||||
render_to_response, redirect, cleaned_markdown_conversion)
|
||||
render_to_response, redirect, cleaned_markdown_conversion, \
|
||||
convert_to_tag_list)
|
||||
from mediagoblin.decorators import require_active_login
|
||||
from mediagoblin.submit import forms as submit_forms, security
|
||||
from mediagoblin.process_media import process_media_initial
|
||||
@ -59,7 +60,7 @@ def submit_start(request):
|
||||
|
||||
entry['media_type'] = u'image' # heh
|
||||
entry['uploader'] = request.user['_id']
|
||||
entry['tags'] = split(request.POST.get('tags'))
|
||||
entry['tags'] = convert_to_tag_list(request.POST.get('tags'))
|
||||
|
||||
# Save, just so we can get the entry id for the sake of using
|
||||
# it to generate the file path
|
||||
|
@ -48,10 +48,6 @@
|
||||
user= media.uploader().username) }}">
|
||||
{{- media.uploader().username }}</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{{ ' '.join(media.tags) }}
|
||||
</p>
|
||||
<br />
|
||||
|
||||
<h3>Comments</h3>
|
||||
@ -114,6 +110,11 @@
|
||||
</p>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if media.tags %}
|
||||
<p>
|
||||
{{ ' '.join(media.tags) }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>Sorry, no such media found.<p/>
|
||||
|
@ -371,6 +371,7 @@ def clean_html(html):
|
||||
|
||||
|
||||
TAGS_DELIMITER = u' '
|
||||
TAGS_CASE_SENSITIVE = False
|
||||
|
||||
def convert_to_tag_list(tag_string):
|
||||
"""
|
||||
@ -379,12 +380,16 @@ def convert_to_tag_list(tag_string):
|
||||
Strips trailing, leading, and internal whitespace, and also converts
|
||||
the user input into an array of tags
|
||||
"""
|
||||
taglist = []
|
||||
if tag_string:
|
||||
taglist = []
|
||||
stripped_tag_string = u' '.join(tag_string.strip().split())
|
||||
for tag in stripped_tag_string.split(TAGS_DELIMITER):
|
||||
if tag.strip(): taglist.append(tag.strip())
|
||||
return taglist
|
||||
if tag.strip():
|
||||
if TAGS_CASE_SENSITIVE:
|
||||
taglist.append(tag.strip())
|
||||
else:
|
||||
taglist.append(tag.strip().lower())
|
||||
return taglist
|
||||
|
||||
|
||||
MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape')
|
||||
|
Loading…
x
Reference in New Issue
Block a user