Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #13038 -- Ensured that readonly fields in the admin have their …

…name added as a CSS class. Thanks to andybak for the report, and javimansilla, fisadev and fgallina for their work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12922 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 90d112785b5caf30507ffc91b74b8f5a7725e4f6 1 parent 653b27d
@freakboy3742 freakboy3742 authored
View
19 django/contrib/admin/helpers.py
@@ -128,7 +128,15 @@ def label_tag(self):
class AdminReadonlyField(object):
def __init__(self, form, field, is_first, model_admin=None):
- self.field = field
+ label = label_for_field(field, form._meta.model, model_admin)
+ # Make self.field look a little bit like a field. This means that
+ # {{ field.name }} must be a useful class name to identify the field.
+ # For convenience, store other field-related data here too.
+ self.field = {
+ 'name': force_unicode(label != '--' and label or ''),
+ 'label': label,
+ 'field': field,
+ }
self.form = form
self.model_admin = model_admin
self.is_first = is_first
@@ -139,10 +147,8 @@ def label_tag(self):
attrs = {}
if not self.is_first:
attrs["class"] = "inline"
- name = forms.forms.pretty_name(
- label_for_field(self.field, self.form._meta.model, self.model_admin)
- )
- contents = force_unicode(escape(name)) + u":"
+ label = forms.forms.pretty_name(self.field['label'])
+ contents = force_unicode(escape(label)) + u":"
return mark_safe('<label%(attrs)s>%(contents)s</label>' % {
"attrs": flatatt(attrs),
"contents": contents,
@@ -151,7 +157,7 @@ def label_tag(self):
def contents(self):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
- field, obj, model_admin = self.field, self.form.instance, self.model_admin
+ field, obj, model_admin = self.field['field'], self.form.instance, self.model_admin
try:
f, attr, value = lookup_field(field, obj, model_admin)
except (AttributeError, ValueError, ObjectDoesNotExist):
@@ -323,4 +329,3 @@ def normalize_dictionary(data_dict):
del data_dict[key]
data_dict[str(key)] = value
return data_dict
-
View
2  django/contrib/admin/templates/admin/includes/fieldset.html
@@ -4,7 +4,7 @@
<div class="description">{{ fieldset.description|safe }}</div>
{% endif %}
{% for line in fieldset %}
- <div class="form-row{% if line.errors %} errors{% endif %} {% for field in line %}{{ field.field.name }} {% endfor %} ">
+ <div class="form-row{% if line.errors %} errors{% endif %}{% for field in line %} {{ field.field.name }}{% endfor %}">
{{ line.errors }}
{% for field in line %}
<div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
View
5 tests/regressiontests/admin_views/tests.py
@@ -1967,6 +1967,11 @@ def test_readonly_get(self):
formats.localize(datetime.date.today() - datetime.timedelta(days=7))
)
+ self.assertContains(response, '<div class="form-row coolness">')
+ self.assertContains(response, '<div class="form-row awesomeness_level">')
+ self.assertContains(response, '<div class="form-row posted">')
+ self.assertContains(response, '<div class="form-row ">')
+
p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)
self.assertContains(response, "%d amount of cool" % p.pk)
Please sign in to comment.
Something went wrong with that request. Please try again.