Author: russellm
Date: 2007-04-27 09:27:07 -0500 (Fri, 27 Apr 2007)
New Revision: 5112
Modified:
django/trunk/django/newforms/forms.py
django/trunk/tests/regressiontests/forms/tests.py
Log:
Fixed #3698 -- Modified newforms labels to only add a colon if the label text
doesn't end with punctuation. Thanks, SmileyChris.
Modified: django/trunk/django/newforms/forms.py
===================================================================
--- django/trunk/django/newforms/forms.py 2007-04-27 14:25:05 UTC (rev
5111)
+++ django/trunk/django/newforms/forms.py 2007-04-27 14:27:07 UTC (rev
5112)
@@ -122,7 +122,14 @@
else:
if errors_on_separate_row and bf_errors:
output.append(error_row % bf_errors)
- label = bf.label and bf.label_tag(escape(bf.label + ':')) or ''
+ if bf.label:
+ label = escape(bf.label)
+ # Only add a colon if the label does not end in
punctuation.
+ if label[-1] not in ':?.!':
+ label += ':'
+ label = bf.label_tag(label) or ''
+ else:
+ label = ''
if field.help_text:
help_text = help_text_html % field.help_text
else:
Modified: django/trunk/tests/regressiontests/forms/tests.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests.py 2007-04-27 14:25:05 UTC
(rev 5111)
+++ django/trunk/tests/regressiontests/forms/tests.py 2007-04-27 14:27:07 UTC
(rev 5112)
@@ -2601,6 +2601,27 @@
<li>Password1: <input type="password" name="password1" /></li>
<li>Password (again): <input type="password" name="password2" /></li>
+Labels for as_* methods will only end in a colon if they don't end in other
+punctuation already.
+>>> class Questions(Form):
+... q1 = CharField(label='The first question')
+... q2 = CharField(label='What is your name?')
+... q3 = CharField(label='The answer to life is:')
+... q4 = CharField(label='Answer this question!')
+... q5 = CharField(label='The last question. Period.')
+>>> print Questions(auto_id=False).as_p()
+<p>The first question: <input type="text" name="q1" /></p>
+<p>What is your name? <input type="text" name="q2" /></p>
+<p>The answer to life is: <input type="text" name="q3" /></p>
+<p>Answer this question! <input type="text" name="q4" /></p>
+<p>The last question. Period. <input type="text" name="q5" /></p>
+>>> print Questions().as_p()
+<p><label for="id_q1">The first question:</label> <input type="text" name="q1"
id="id_q1" /></p>
+<p><label for="id_q2">What is your name?</label> <input type="text" name="q2"
id="id_q2" /></p>
+<p><label for="id_q3">The answer to life is:</label> <input type="text"
name="q3" id="id_q3" /></p>
+<p><label for="id_q4">Answer this question!</label> <input type="text"
name="q4" id="id_q4" /></p>
+<p><label for="id_q5">The last question. Period.</label> <input type="text"
name="q5" id="id_q5" /></p>
+
A label can be a Unicode object or a bytestring with special characters.
>>> class UserRegistration(Form):
... username = CharField(max_length=10, label='ŠĐĆŽćžšđ')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---