Made fix for #9321 less buggy and more effective.

Don't try to be smart about building a good-looking help string
because it evaluates translations too early, simply use the same old
strategy as before. Thanks Donald Stufft for the report.

Also, actually fix the case reported by the OP by special-casing
CheckboxSelectMultiple.

Added tests.

Refs #9321.
This commit is contained in:
Ramiro Morales 2013-05-21 18:32:39 -03:00
parent 01769823f1
commit 8c2fd050f8
5 changed files with 58 additions and 8 deletions

View file

@ -255,3 +255,7 @@ class Colour(models.Model):
class ColourfulItem(models.Model):
name = models.CharField(max_length=50)
colours = models.ManyToManyField(Colour)
class ArticleStatusNote(models.Model):
name = models.CharField(max_length=20)
status = models.ManyToManyField(ArticleStatus)

View file

@ -24,7 +24,7 @@ from .models import (Article, ArticleStatus, BetterAuthor, BigInt,
DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
ImprovedArticleWithParentLink, Inventory, Post, Price,
Product, TextFile, AuthorProfile, Colour, ColourfulItem,
test_images)
ArticleStatusNote, test_images)
if test_images:
from .models import ImageFile, OptionalImageFile
@ -234,6 +234,20 @@ class ColourfulItemForm(forms.ModelForm):
model = ColourfulItem
fields = '__all__'
# model forms for testing work on #9321:
class StatusNoteForm(forms.ModelForm):
class Meta:
model = ArticleStatusNote
fields = '__all__'
class StatusNoteCBM2mForm(forms.ModelForm):
class Meta:
model = ArticleStatusNote
fields = '__all__'
widgets = {'status': forms.CheckboxSelectMultiple}
class ModelFormBaseTest(TestCase):
def test_base_form(self):
@ -1677,3 +1691,22 @@ class OldFormForXTests(TestCase):
<option value="%(blue_pk)s">Blue</option>
</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>"""
% {'blue_pk': colour.pk})
class M2mHelpTextTest(TestCase):
"""Tests for ticket #9321."""
def test_multiple_widgets(self):
"""Help text of different widgets for ManyToManyFields model fields"""
dreaded_help_text = '<span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span>'
# Default widget (SelectMultiple):
std_form = StatusNoteForm()
self.assertInHTML(dreaded_help_text, std_form.as_p())
# Overridden widget (CheckboxSelectMultiple, a subclass of
# SelectMultiple but with a UI that doesn't involve Control/Command
# keystrokes to extend selection):
form = StatusNoteCBM2mForm()
html = form.as_p()
self.assertInHTML('<ul id="id_status">', html)
self.assertInHTML(dreaded_help_text, html, count=0)