diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2013-05-21 18:32:39 -0300 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2013-05-23 07:49:29 -0300 |
| commit | 8c2fd050f80f528cc1609c1a7f16901194834831 (patch) | |
| tree | eb8a44065ec57c9fefb6ef6914247c8a27637769 /tests/model_forms | |
| parent | 01769823f13df6e922faf63a2ac07293dc54b176 (diff) | |
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.
Diffstat (limited to 'tests/model_forms')
| -rw-r--r-- | tests/model_forms/models.py | 4 | ||||
| -rw-r--r-- | tests/model_forms/tests.py | 35 |
2 files changed, 38 insertions, 1 deletions
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index a79d9b8c5b..9c5e097106 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -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) diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index db8b6cf0e7..5219804e0c 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -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) |
