Ticket #20805: 20805.diff

File 20805.diff, 3.5 KB (added by Tim Graham, 11 years ago)
  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    index 3ffb85e..ebf8c5c 100644
    a b class AdminField(object):  
    125125        contents = conditional_escape(force_text(self.field.label))
    126126        if self.is_checkbox:
    127127            classes.append('vCheckboxLabel')
    128         else:
    129             contents += ':'
     128
    130129        if self.field.field.required:
    131130            classes.append('required')
    132131        if not self.is_first:
    133132            classes.append('inline')
    134133        attrs = {'class': ' '.join(classes)} if classes else {}
    135         return self.field.label_tag(contents=mark_safe(contents), attrs=attrs)
     134        return self.field.label_tag(contents=mark_safe(contents), attrs=attrs,
     135                                    include_label_suffix=not self.is_checkbox)
    136136
    137137    def errors(self):
    138138        return mark_safe(self.field.errors.as_ul())
  • django/forms/forms.py

    diff --git a/django/forms/forms.py b/django/forms/forms.py
    index e144eb6..a914d0e 100644
    a b class BoundField(object):  
    509509            )
    510510        return self.field.prepare_value(data)
    511511
    512     def label_tag(self, contents=None, attrs=None):
     512    def label_tag(self, contents=None, attrs=None, include_label_suffix=True):
    513513        """
    514514        Wraps the given contents in a <label>, if the field has an ID attribute.
    515515        contents should be 'mark_safe'd to avoid HTML escaping. If contents
    class BoundField(object):  
    521521        # Only add the suffix if the label does not end in punctuation.
    522522        # Translators: If found as last label character, these punctuation
    523523        # characters will prevent the default label_suffix to be appended to the label
    524         if self.form.label_suffix and contents and contents[-1] not in _(':?.!'):
     524        if include_label_suffix and self.form.label_suffix and contents and contents[-1] not in _(':?.!'):
    525525            contents = format_html('{0}{1}', contents, self.form.label_suffix)
    526526        widget = self.field.widget
    527527        id_ = widget.attrs.get('id') or self.auto_id
  • tests/admin_util/tests.py

    diff --git a/tests/admin_util/tests.py b/tests/admin_util/tests.py
    index 637f643..4a9a203 100644
    a b class UtilTests(SimpleTestCase):  
    301301        self.assertHTMLEqual(helpers.AdminField(form, 'text', is_first=False).label_tag(),
    302302                             '<label for="id_text" class="required inline"><i>text</i>:</label>')
    303303        self.assertHTMLEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
    304                              '<label for="id_cb" class="vCheckboxLabel required inline"><i>cb</i>:</label>')
     304                             '<label for="id_cb" class="vCheckboxLabel required inline"><i>cb</i></label>')
    305305
    306306        # normal strings needs to be escaped
    307307        class MyForm(forms.Form):
    class UtilTests(SimpleTestCase):  
    312312        self.assertHTMLEqual(helpers.AdminField(form, 'text', is_first=False).label_tag(),
    313313                             '<label for="id_text" class="required inline">&amp;text:</label>')
    314314        self.assertHTMLEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
    315                              '<label for="id_cb" class="vCheckboxLabel required inline">&amp;cb:</label>')
     315                             '<label for="id_cb" class="vCheckboxLabel required inline">&amp;cb</label>')
    316316
    317317    def test_flatten_fieldsets(self):
    318318        """
Back to Top