Commit f3657783 by Carl Meyer

quote multiword tags so they round-trip

parent 4b0d0dc4
...@@ -42,7 +42,7 @@ If, when saving a form, you use the ``commit=False`` option you'll need to call ...@@ -42,7 +42,7 @@ If, when saving a form, you use the ``commit=False`` option you'll need to call
form with normal many to many fields on it:: form with normal many to many fields on it::
if request.method == "POST": if request.method == "POST":
form = MyFormClass(requets.POST) form = MyFormClass(request.POST)
if form.is_valid(): if form.is_valid():
obj = form.save(commit=False) obj = form.save(commit=False)
obj.user = request.user obj.user = request.user
......
...@@ -241,6 +241,10 @@ class TaggableFormTestCase(BaseTaggingTestCase): ...@@ -241,6 +241,10 @@ class TaggableFormTestCase(BaseTaggingTestCase):
f = self.form_class(instance=apple) f = self.form_class(instance=apple)
self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="&quot;has,comma&quot;, delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>""") self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="&quot;has,comma&quot;, delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>""")
apple.tags.add('has space')
f = self.form_class(instance=apple)
self.assertEqual(str(f), """<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>\n<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="&quot;has space&quot;, &quot;has,comma&quot;, delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>""")
class TaggableFormDirectTestCase(TaggableFormTestCase): class TaggableFormDirectTestCase(TaggableFormTestCase):
form_class = DirectFoodForm form_class = DirectFoodForm
...@@ -330,7 +334,7 @@ class TagStringParseTestCase(UnitTestCase): ...@@ -330,7 +334,7 @@ class TagStringParseTestCase(UnitTestCase):
spaces = Tag.objects.create(name='spa ces') spaces = Tag.objects.create(name='spa ces')
comma = Tag.objects.create(name='com,ma') comma = Tag.objects.create(name='com,ma')
self.assertEqual(edit_string_for_tags([plain]), u'plain') self.assertEqual(edit_string_for_tags([plain]), u'plain')
self.assertEqual(edit_string_for_tags([plain, spaces]), u'plain, spa ces') self.assertEqual(edit_string_for_tags([plain, spaces]), u'"spa ces", plain')
self.assertEqual(edit_string_for_tags([plain, spaces, comma]), u'"com,ma", plain, spa ces') self.assertEqual(edit_string_for_tags([plain, spaces, comma]), u'"com,ma", "spa ces", plain')
self.assertEqual(edit_string_for_tags([plain, comma]), u'"com,ma", plain') self.assertEqual(edit_string_for_tags([plain, comma]), u'"com,ma", plain')
self.assertEqual(edit_string_for_tags([comma, spaces]), u'"com,ma", spa ces') self.assertEqual(edit_string_for_tags([comma, spaces]), u'"com,ma", "spa ces"')
...@@ -110,7 +110,7 @@ def edit_string_for_tags(tags): ...@@ -110,7 +110,7 @@ def edit_string_for_tags(tags):
names = [] names = []
for tag in tags: for tag in tags:
name = tag.name name = tag.name
if u',' in name: if u',' in name or u' ' in name:
names.append('"%s"' % name) names.append('"%s"' % name)
else: else:
names.append(name) names.append(name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment