From 8a4a8023d61cb31093db7b511e58ea3502e47cb6 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 27 Apr 2007 14:27:07 +0000 Subject: [PATCH] Fixed #3698 -- Modified newforms labels to only add a colon if the label text doesn't end with punctuation. Thanks, SmileyChris. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5112 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/forms.py | 9 ++++++++- tests/regressiontests/forms/tests.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 3df7a9e834e..9fafd207874 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -122,7 +122,14 @@ class BaseForm(StrAndUnicode): 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: diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index e0d05a2c89d..0d3a65277c0 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -2601,6 +2601,27 @@ underscores converted to spaces, and the initial letter capitalized.
  • Password1:
  • Password (again):
  • +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() +

    The first question:

    +

    What is your name?

    +

    The answer to life is:

    +

    Answer this question!

    +

    The last question. Period.

    +>>> print Questions().as_p() +

    +

    +

    +

    +

    + A label can be a Unicode object or a bytestring with special characters. >>> class UserRegistration(Form): ... username = CharField(max_length=10, label='ŠĐĆŽćžšđ')