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_debug_mode = boolean(default=True)
|
||||||
email_sender_address = string(default="notice@mediagoblin.example.org")
|
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:
|
# By default not set, but you might want something like:
|
||||||
# "%(here)s/user_dev/templates/"
|
# "%(here)s/user_dev/templates/"
|
||||||
local_templates = string()
|
local_templates = string()
|
||||||
|
@ -19,9 +19,9 @@ from webob import exc
|
|||||||
from string import split
|
from string import split
|
||||||
|
|
||||||
from mediagoblin import messages
|
from mediagoblin import messages
|
||||||
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.util import (
|
from mediagoblin.util import (
|
||||||
render_to_response, redirect, clean_html, TAGS_DELIMITER, \
|
render_to_response, redirect, clean_html, convert_to_tag_list)
|
||||||
convert_to_tag_list)
|
|
||||||
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 +39,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 = TAGS_DELIMITER.join(media['tags']))
|
tags = mg_globals.app_config['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
|
||||||
|
@ -371,10 +371,6 @@ def clean_html(html):
|
|||||||
return HTML_CLEANER.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):
|
def convert_to_tag_list(tag_string):
|
||||||
"""
|
"""
|
||||||
Filter input from incoming string containing user tags,
|
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())
|
stripped_tag_string = u' '.join(tag_string.strip().split())
|
||||||
|
|
||||||
# Split the tag string into a list of tags
|
# 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
|
# Do not permit duplicate tags
|
||||||
if tag.strip() and tag not in taglist:
|
if tag.strip() and tag not in taglist:
|
||||||
|
|
||||||
if TAGS_CASE_SENSITIVE:
|
if mg_globals.app_config['tags_case_sensitive']:
|
||||||
taglist.append(tag.strip())
|
taglist.append(tag.strip())
|
||||||
else:
|
else:
|
||||||
taglist.append(tag.strip().lower())
|
taglist.append(tag.strip().lower())
|
||||||
@ -411,12 +408,12 @@ def tag_length_validator(form, field):
|
|||||||
tags = convert_to_tag_list(field.data)
|
tags = convert_to_tag_list(field.data)
|
||||||
too_long_tags = [
|
too_long_tags = [
|
||||||
tag for tag in 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:
|
if too_long_tags:
|
||||||
raise wtforms.ValidationError(
|
raise wtforms.ValidationError(
|
||||||
TOO_LONG_TAG_WARNING % (
|
TOO_LONG_TAG_WARNING % (mg_globals.app_config['tags_max_length'], \
|
||||||
TAGS_MAX_LENGTH, ', '.join(too_long_tags)))
|
', '.join(too_long_tags)))
|
||||||
|
|
||||||
|
|
||||||
MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape')
|
MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user