Commits

Luke Plant committed a8c8cb9

Fixed bug with create_update view, and added stripping of some nasty chars in tags

Comments (0)

Files changed (1)

django/tagging/views.py

+import string
 from django.template import RequestContext
 from django.http import Http404, HttpResponseRedirect
 from django.shortcuts import render_to_response
         raise Http404()
 
     base_attrs = _get_base_attrs_for_objs(creator, target)
-    
     search_attrs = _get_search_attrs(base_attrs)
+
     tags = Tag.objects.filter(**search_attrs)
 
     currenttagset = set([tag.text for tag in tags])
     
     if request.POST.get('save'):
-        newtagset = set(request.POST.get('text', '').split())
+        # remove some possibly troublesome chars:
+        text = request.POST.get('text', '').translate(string.maketrans('', ''), "<>&\"'?")
+        newtagset = set(text.split())
+        # Delete ones that have been removed
         for tagname in currenttagset - newtagset:
             Tag.objects.filter(**search_attrs).filter(text=tagname).delete()
+        # Add new ones
         for tagname in newtagset - currenttagset:
             t = Tag(**base_attrs)
-            t.text = tagname.strip("<>&\"'?") # remove troublesome chars
+            t.text = tagname
             t.save()
         if redirect_url is None:
             redirect_url = request.POST.get('redirect_url', None)
     c.update(base_attrs)
     c['target'] = tagging_utils.get_object(base_attrs['target_id'], base_attrs['target_ct_id'])
     c['creator'] = tagging_utils.get_object(base_attrs['creator_id'], base_attrs['creator_ct_id'])
-    c['textlist'] = " ".join(currenttagset)
+    c['textlist'] = list(currenttagset)
+    c['text'] = " ".join(currenttagset)
     if redirect_url:
         c['redirect_url'] = redirect_url
     ctx = RequestContext(request, c)