summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-07-26 14:43:46 -0400
committerTim Graham <timograham@gmail.com>2013-07-26 14:45:38 -0400
commit8676318d2dae9a570d2314e4e6da8c00aaf2e2a0 (patch)
tree86e3bd1bd11dd09d9aaf288357f9feacffb3d363 /django
parent2a979d2a7bec485e4b90b7ae99ace0dd16faa948 (diff)
Fixed #20805 -- Removed an extra colon beside checkboxes in the admin.
Thanks CollinAnderson for the report.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/helpers.py8
-rw-r--r--django/forms/forms.py9
2 files changed, 11 insertions, 6 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index 3ffb85e6c6..b6d5bde932 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -125,14 +125,16 @@ class AdminField(object):
contents = conditional_escape(force_text(self.field.label))
if self.is_checkbox:
classes.append('vCheckboxLabel')
- else:
- contents += ':'
+
if self.field.field.required:
classes.append('required')
if not self.is_first:
classes.append('inline')
attrs = {'class': ' '.join(classes)} if classes else {}
- return self.field.label_tag(contents=mark_safe(contents), attrs=attrs)
+ # checkboxes should not have a label suffix as the checkbox appears
+ # to the left of the label.
+ return self.field.label_tag(contents=mark_safe(contents), attrs=attrs,
+ label_suffix='' if self.is_checkbox else None)
def errors(self):
return mark_safe(self.field.errors.as_ul())
diff --git a/django/forms/forms.py b/django/forms/forms.py
index e144eb60f8..ad5daf4416 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -509,20 +509,23 @@ class BoundField(object):
)
return self.field.prepare_value(data)
- def label_tag(self, contents=None, attrs=None):
+ def label_tag(self, contents=None, attrs=None, label_suffix=None):
"""
Wraps the given contents in a <label>, if the field has an ID attribute.
contents should be 'mark_safe'd to avoid HTML escaping. If contents
aren't given, uses the field's HTML-escaped label.
If attrs are given, they're used as HTML attributes on the <label> tag.
+
+ label_suffix allows overriding the form's label_suffix.
"""
contents = contents or self.label
# Only add the suffix if the label does not end in punctuation.
# Translators: If found as last label character, these punctuation
# characters will prevent the default label_suffix to be appended to the label
- if self.form.label_suffix and contents and contents[-1] not in _(':?.!'):
- contents = format_html('{0}{1}', contents, self.form.label_suffix)
+ label_suffix = label_suffix if label_suffix is not None else self.form.label_suffix
+ if label_suffix and contents and contents[-1] not in _(':?.!'):
+ contents = format_html('{0}{1}', contents, label_suffix)
widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id
if id_: