use config_spec.ini to store tag parsing directives
authorCaleb Forbes Davis V <caldavis@gmail.com>
Tue, 26 Jul 2011 04:46:36 +0000 (23:46 -0500)
committerCaleb Forbes Davis V <caldavis@gmail.com>
Tue, 26 Jul 2011 04:46:36 +0000 (23:46 -0500)
mediagoblin/config_spec.ini
mediagoblin/edit/views.py
mediagoblin/util.py

index aadf5c2106a4fc64d124bfe45200860ade49ce8a..5aae6439d86bba5a9c6d6762b27f9f122caf4432 100644 (file)
@@ -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()
index b3d239e1e00b50d50f52ceecbd25b8b42ec506e8..3193bfa348a40b372225df3dbec35cbc3378b0ca 100644 (file)
@@ -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
index a84e07c4c9da03b8840c1436566081481379a7d4..8bb90acf77c5c4875c724c576533a7923199a786 100644 (file)
@@ -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')