uses standard functions instead of form filters and fixes taglist default
authorCaleb Forbes Davis V <caldavis@gmail.com>
Wed, 13 Jul 2011 03:26:10 +0000 (22:26 -0500)
committerCaleb Forbes Davis V <caldavis@gmail.com>
Wed, 13 Jul 2011 03:43:26 +0000 (22:43 -0500)
- 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

mediagoblin/edit/forms.py
mediagoblin/edit/views.py
mediagoblin/submit/forms.py
mediagoblin/submit/views.py
mediagoblin/templates/mediagoblin/user_pages/media.html
mediagoblin/util.py

index e13cfaa9e736796efdcdc5d8a24b2b10f58179af..21c8509afec8eb1214c1b51afdaf09ad8cf1a2b3 100644 (file)
@@ -17,8 +17,6 @@
 
 import wtforms
 
-from mediagoblin.util import convert_to_tag_list
-
 
 class EditForm(wtforms.Form):
     title = wtforms.TextField(
index 0c4fd7351f57b7eb4cd7bd8242db71e4f1a32e09..0432024ee970da27590d117b4f9934a96bfc7c2b 100644 (file)
@@ -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",
index e13d542528a77c06065731b05422bba8f1dc6144..0e0fd08694929a53150b6614092a3e352346b276 100644 (file)
@@ -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')
index cdd587860aee21ddb6c9c4edd2b56ba5b3630359..46ec4cea8700720d4e1b16df5906e9b1b80bdbb2 100644 (file)
@@ -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
index 1c26388090b732f0eb58ad7e659bd27e5642bb85..47d5db35acd30be49b4a012f37b77dead5628929 100644 (file)
                                    user= media.uploader().username) }}">
           {{- media.uploader().username }}</a>
       </p>
-      
-      <p>
-        {{ ' '.join(media.tags) }}
-      </p>
       <br />
 
       <h3>Comments</h3>
           </p>
         {% endif %}
       </p>
+      {% if media.tags %}
+        <p>
+          {{ ' '.join(media.tags) }}
+        </p>
+      {% endif %}
     </div>
   {% else %}
     <p>Sorry, no such media found.<p/>
index 4421bec4436b8b6e1b011a250899e97cc29c78b7..f2a2793b44389c7c728ffdbbdccba170d346bb74 100644 (file)
@@ -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')