Django

Code

Changeset 5112

Show
Ignore:
Timestamp:
04/27/07 09:27:07 (2 years ago)
Author:
russellm
Message:

Fixed #3698 -- Modified newforms labels to only add a colon if the label text doesn't end with punctuation. Thanks, SmileyChris?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/forms.py

    r5091 r5112  
    123123                if errors_on_separate_row and bf_errors: 
    124124                    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 = '' 
    126133                if field.help_text: 
    127134                    help_text = help_text_html % field.help_text 
  • django/trunk/tests/regressiontests/forms/tests.py

    r5088 r5112  
    26022602<li>Password (again): <input type="password" name="password2" /></li> 
    26032603 
     2604Labels for as_* methods will only end in a colon if they don't end in other 
     2605punctuation 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 
    26042625A label can be a Unicode object or a bytestring with special characters. 
    26052626>>> class UserRegistration(Form):