Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3698 -- Modified newforms labels to only add a colon if the la…

…bel text doesn't end with punctuation. Thanks, SmileyChris.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5112 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8a4a8023d61cb31093db7b511e58ea3502e47cb6 1 parent 1c2fdf1
Russell Keith-Magee authored
9  django/newforms/forms.py
@@ -122,7 +122,14 @@ def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_
122 122
             else:
123 123
                 if errors_on_separate_row and bf_errors:
124 124
                     output.append(error_row % bf_errors)
125  
-                label = bf.label and bf.label_tag(escape(bf.label + ':')) or ''
  125
+                if bf.label:
  126
+                    label = escape(bf.label)
  127
+                    # Only add a colon if the label does not end in punctuation.
  128
+                    if label[-1] not in ':?.!':
  129
+                        label += ':'
  130
+                    label = bf.label_tag(label) or ''
  131
+                else:
  132
+                    label = ''
126 133
                 if field.help_text:
127 134
                     help_text = help_text_html % field.help_text
128 135
                 else:
21  tests/regressiontests/forms/tests.py
@@ -2601,6 +2601,27 @@
2601 2601
 <li>Password1: <input type="password" name="password1" /></li>
2602 2602
 <li>Password (again): <input type="password" name="password2" /></li>
2603 2603
 
  2604
+Labels for as_* methods will only end in a colon if they don't end in other
  2605
+punctuation already.
  2606
+>>> class Questions(Form):
  2607
+...    q1 = CharField(label='The first question')
  2608
+...    q2 = CharField(label='What is your name?')
  2609
+...    q3 = CharField(label='The answer to life is:')
  2610
+...    q4 = CharField(label='Answer this question!')
  2611
+...    q5 = CharField(label='The last question. Period.')
  2612
+>>> print Questions(auto_id=False).as_p()
  2613
+<p>The first question: <input type="text" name="q1" /></p>
  2614
+<p>What is your name? <input type="text" name="q2" /></p>
  2615
+<p>The answer to life is: <input type="text" name="q3" /></p>
  2616
+<p>Answer this question! <input type="text" name="q4" /></p>
  2617
+<p>The last question. Period. <input type="text" name="q5" /></p>
  2618
+>>> print Questions().as_p()
  2619
+<p><label for="id_q1">The first question:</label> <input type="text" name="q1" id="id_q1" /></p>
  2620
+<p><label for="id_q2">What is your name?</label> <input type="text" name="q2" id="id_q2" /></p>
  2621
+<p><label for="id_q3">The answer to life is:</label> <input type="text" name="q3" id="id_q3" /></p>
  2622
+<p><label for="id_q4">Answer this question!</label> <input type="text" name="q4" id="id_q4" /></p>
  2623
+<p><label for="id_q5">The last question. Period.</label> <input type="text" name="q5" id="id_q5" /></p>
  2624
+
2604 2625
 A label can be a Unicode object or a bytestring with special characters.
2605 2626
 >>> class UserRegistration(Form):
2606 2627
 ...    username = CharField(max_length=10, label='ŠĐĆŽćžšđ')

0 notes on commit 8a4a802

Please sign in to comment.
Something went wrong with that request. Please try again.