use config_spec.ini to store tag parsing directives
This commit is contained in:
parent
909371cdce
commit
10d7496da2
@ -21,6 +21,11 @@ direct_remote_path = string(default="/mgoblin_static/")
|
||||
email_debug_mode = boolean(default=True)
|
||||
email_sender_address = string(default="notice@mediagoblin.example.org")
|
||||
|
||||
# tag parsing
|
||||
tags_delimiter = string(default=",")
|
||||
tags_case_sensitive = boolean(default=False)
|
||||
tags_max_length = integer(default=50)
|
||||
|
||||
# By default not set, but you might want something like:
|
||||
# "%(here)s/user_dev/templates/"
|
||||
local_templates = string()
|
||||
|
@ -19,9 +19,9 @@ from webob import exc
|
||||
from string import split
|
||||
|
||||
from mediagoblin import messages
|
||||
from mediagoblin import mg_globals
|
||||
from mediagoblin.util import (
|
||||
render_to_response, redirect, clean_html, TAGS_DELIMITER, \
|
||||
convert_to_tag_list)
|
||||
render_to_response, redirect, clean_html, 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
|
||||
@ -39,7 +39,7 @@ def edit_media(request, media):
|
||||
title = media['title'],
|
||||
slug = media['slug'],
|
||||
description = media['description'],
|
||||
tags = TAGS_DELIMITER.join(media['tags']))
|
||||
tags = mg_globals.app_config['tags_delimiter'].join(media['tags']))
|
||||
|
||||
if request.method == 'POST' and form.validate():
|
||||
# Make sure there isn't already a MediaEntry with such a slug
|
||||
|
@ -371,10 +371,6 @@ def clean_html(html):
|
||||
return HTML_CLEANER.clean_html(html)
|
||||
|
||||
|
||||
TAGS_DELIMITER = u' '
|
||||
TAGS_CASE_SENSITIVE = False
|
||||
TAGS_MAX_LENGTH = 50
|
||||
|
||||
def convert_to_tag_list(tag_string):
|
||||
"""
|
||||
Filter input from incoming string containing user tags,
|
||||
@ -389,12 +385,13 @@ def convert_to_tag_list(tag_string):
|
||||
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(
|
||||
mg_globals.app_config['tags_delimiter']):
|
||||
|
||||
# Do not permit duplicate tags
|
||||
if tag.strip() and tag not in taglist:
|
||||
|
||||
if TAGS_CASE_SENSITIVE:
|
||||
if mg_globals.app_config['tags_case_sensitive']:
|
||||
taglist.append(tag.strip())
|
||||
else:
|
||||
taglist.append(tag.strip().lower())
|
||||
@ -411,12 +408,12 @@ def tag_length_validator(form, field):
|
||||
tags = convert_to_tag_list(field.data)
|
||||
too_long_tags = [
|
||||
tag for tag in tags
|
||||
if len(tag) > TAGS_MAX_LENGTH]
|
||||
if len(tag) > mg_globals.app_config['tags_max_length']]
|
||||
|
||||
if too_long_tags:
|
||||
raise wtforms.ValidationError(
|
||||
TOO_LONG_TAG_WARNING % (
|
||||
TAGS_MAX_LENGTH, ', '.join(too_long_tags)))
|
||||
TOO_LONG_TAG_WARNING % (mg_globals.app_config['tags_max_length'], \
|
||||
', '.join(too_long_tags)))
|
||||
|
||||
|
||||
MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape')
|
||||
|
Loading…
x
Reference in New Issue
Block a user