changes tags to a list of dicts in the db, adding tag slugs
- adds a function to convert the tag list of dicts to a text string properly delimited for loading into forms - tag string conversion function updated to generate list of dicts - updates all mentions of the conversion of the string to the tags db object - adds a tags template utility and updates the media template accordingly
This commit is contained in:
parent
97e4498c10
commit
0712a06dc6
@ -82,7 +82,7 @@ class MediaEntry(Document):
|
|||||||
'media_type': unicode,
|
'media_type': unicode,
|
||||||
'media_data': dict, # extra data relevant to this media_type
|
'media_data': dict, # extra data relevant to this media_type
|
||||||
'plugin_data': dict, # plugins can dump stuff here.
|
'plugin_data': dict, # plugins can dump stuff here.
|
||||||
'tags': [unicode],
|
'tags': [dict],
|
||||||
'state': unicode,
|
'state': unicode,
|
||||||
|
|
||||||
# For now let's assume there can only be one main file queued
|
# For now let's assume there can only be one main file queued
|
||||||
|
@ -21,7 +21,8 @@ from string import split
|
|||||||
from mediagoblin import messages
|
from mediagoblin import messages
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.util import (
|
from mediagoblin.util import (
|
||||||
render_to_response, redirect, clean_html, convert_to_tag_list)
|
render_to_response, redirect, clean_html, convert_to_tag_list_of_dicts,
|
||||||
|
media_tags_as_string)
|
||||||
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
|
||||||
@ -39,7 +40,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 = mg_globals.app_config['tags_delimiter'].join(media['tags']))
|
tags = media_tags_as_string(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
|
||||||
@ -55,7 +56,8 @@ def edit_media(request, media):
|
|||||||
else:
|
else:
|
||||||
media['title'] = request.POST['title']
|
media['title'] = request.POST['title']
|
||||||
media['description'] = request.POST.get('description')
|
media['description'] = request.POST.get('description')
|
||||||
media['tags'] = convert_to_tag_list(request.POST.get('tags'))
|
media['tags'] = convert_to_tag_list_of_dicts(
|
||||||
|
request.POST.get('tags'))
|
||||||
|
|
||||||
md = markdown.Markdown(
|
md = markdown.Markdown(
|
||||||
safe_mode = 'escape')
|
safe_mode = 'escape')
|
||||||
|
@ -22,7 +22,7 @@ from werkzeug.utils import secure_filename
|
|||||||
|
|
||||||
from mediagoblin.util import (
|
from mediagoblin.util import (
|
||||||
render_to_response, redirect, cleaned_markdown_conversion, \
|
render_to_response, redirect, cleaned_markdown_conversion, \
|
||||||
convert_to_tag_list)
|
convert_to_tag_list_of_dicts)
|
||||||
from mediagoblin.decorators import require_active_login
|
from mediagoblin.decorators import require_active_login
|
||||||
from mediagoblin.submit import forms as submit_forms, security
|
from mediagoblin.submit import forms as submit_forms, security
|
||||||
from mediagoblin.process_media import process_media_initial
|
from mediagoblin.process_media import process_media_initial
|
||||||
@ -62,7 +62,8 @@ def submit_start(request):
|
|||||||
entry['uploader'] = request.user['_id']
|
entry['uploader'] = request.user['_id']
|
||||||
|
|
||||||
# Process the user's folksonomy "tags"
|
# Process the user's folksonomy "tags"
|
||||||
entry['tags'] = convert_to_tag_list(request.POST.get('tags'))
|
entry['tags'] = convert_to_tag_list_of_dicts(
|
||||||
|
request.POST.get('tags'))
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -111,9 +111,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% if media.tags %}
|
{% if media.tags %}
|
||||||
<p>
|
{% include "mediagoblin/utils/tags.html" %}
|
||||||
{{ ' '.join(media.tags) }}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
25
mediagoblin/templates/mediagoblin/utils/tags.html
Normal file
25
mediagoblin/templates/mediagoblin/utils/tags.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{#
|
||||||
|
# GNU MediaGoblin -- federated, autonomous media hosting
|
||||||
|
# Copyright (C) 2011 Free Software Foundation, Inc
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#}
|
||||||
|
|
||||||
|
{% block tags_content -%}
|
||||||
|
<ul class="mediaentry_tags">
|
||||||
|
{% for tag in media.tags %}
|
||||||
|
<li class="tag">{{ tag['name'] }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
@ -371,7 +371,7 @@ def clean_html(html):
|
|||||||
return HTML_CLEANER.clean_html(html)
|
return HTML_CLEANER.clean_html(html)
|
||||||
|
|
||||||
|
|
||||||
def convert_to_tag_list(tag_string):
|
def convert_to_tag_list_of_dicts(tag_string):
|
||||||
"""
|
"""
|
||||||
Filter input from incoming string containing user tags,
|
Filter input from incoming string containing user tags,
|
||||||
|
|
||||||
@ -389,15 +389,29 @@ def convert_to_tag_list(tag_string):
|
|||||||
mg_globals.app_config['tags_delimiter']):
|
mg_globals.app_config['tags_delimiter']):
|
||||||
|
|
||||||
# Do not permit duplicate tags
|
# Do not permit duplicate tags
|
||||||
if tag.strip() and tag not in taglist:
|
if tag.strip() and tag.strip() not in taglist:
|
||||||
|
|
||||||
if mg_globals.app_config['tags_case_sensitive']:
|
if mg_globals.app_config['tags_case_sensitive']:
|
||||||
taglist.append(tag.strip())
|
taglist.append({'name': tag.strip(),
|
||||||
|
'slug': slugify(tag.strip())})
|
||||||
else:
|
else:
|
||||||
taglist.append(tag.strip().lower())
|
taglist.append({'name': tag.strip().lower(),
|
||||||
|
'slug': slugify(tag.strip().lower())})
|
||||||
return taglist
|
return taglist
|
||||||
|
|
||||||
|
|
||||||
|
def media_tags_as_string(media_entry_tags):
|
||||||
|
"""
|
||||||
|
Generate a string from a media item's tags, stored as a list of dicts
|
||||||
|
|
||||||
|
This is the opposite of convert_to_tag_list_of_dicts
|
||||||
|
"""
|
||||||
|
media_tag_string = ''
|
||||||
|
if media_entry_tags:
|
||||||
|
media_tag_string = mg_globals.app_config['tags_delimiter'].join(
|
||||||
|
[tag['name'] for tag in media_entry_tags])
|
||||||
|
return media_tag_string
|
||||||
|
|
||||||
TOO_LONG_TAG_WARNING = \
|
TOO_LONG_TAG_WARNING = \
|
||||||
u'Tags must be shorter than %s characters. Tags that are too long: %s'
|
u'Tags must be shorter than %s characters. Tags that are too long: %s'
|
||||||
|
|
||||||
@ -405,10 +419,10 @@ def tag_length_validator(form, field):
|
|||||||
"""
|
"""
|
||||||
Make sure tags do not exceed the maximum tag length.
|
Make sure tags do not exceed the maximum tag length.
|
||||||
"""
|
"""
|
||||||
tags = convert_to_tag_list(field.data)
|
tags = convert_to_tag_list_of_dicts(field.data)
|
||||||
too_long_tags = [
|
too_long_tags = [
|
||||||
tag for tag in tags
|
tag['name'] for tag in tags
|
||||||
if len(tag) > mg_globals.app_config['tags_max_length']]
|
if len(tag['name']) > mg_globals.app_config['tags_max_length']]
|
||||||
|
|
||||||
if too_long_tags:
|
if too_long_tags:
|
||||||
raise wtforms.ValidationError(
|
raise wtforms.ValidationError(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user