From 8c2fd050f80f528cc1609c1a7f16901194834831 Mon Sep 17 00:00:00 2001
From: Ramiro Morales
Date: Tue, 21 May 2013 18:32:39 -0300
Subject: 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.
---
tests/model_forms/models.py | 4 ++++
tests/model_forms/tests.py | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
(limited to 'tests/model_forms')
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):
Hold down "Control", or "Command" on a Mac, to select more than one.
"""
% {'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 = ' Hold down "Control", or "Command" on a Mac, to select more than one.'
+
+ # 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('