Ticket #13038: bug13038.patch

File bug13038.patch, 3.3 KB (added by Fabián Ezequiel Gallina, 15 years ago)

Patch for adding css classes to read only fields.

  • django/contrib/admin/helpers.py

     
    128128
    129129class AdminReadonlyField(object):
    130130    def __init__(self, form, field, is_first, model_admin=None):
    131         self.field = field
     131        self.field_name = field
    132132        self.form = form
    133133        self.model_admin = model_admin
    134134        self.is_first = is_first
     
    140140        if not self.is_first:
    141141            attrs["class"] = "inline"
    142142        name = forms.forms.pretty_name(
    143             label_for_field(self.field, self.model_admin.model, self.model_admin)
     143            label_for_field(self.field_name, self.model_admin.model, self.model_admin)
    144144        )
    145145        contents = force_unicode(escape(name)) + u":"
    146146        return mark_safe('<label%(attrs)s>%(contents)s</label>' % {
     
    151151    def contents(self):
    152152        from django.contrib.admin.templatetags.admin_list import _boolean_icon
    153153        from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
    154         field, obj, model_admin = self.field, self.form.instance, self.model_admin
     154        field, obj, model_admin = self.field_name, self.form.instance, self.model_admin
    155155        try:
    156156            f, attr, value = lookup_field(field, obj, model_admin)
    157157        except (AttributeError, ObjectDoesNotExist):
     
    323323            del data_dict[key]
    324324            data_dict[str(key)] = value
    325325    return data_dict
    326 
  • django/contrib/admin/templates/admin/includes/fieldset.html

     
    44        <div class="description">{{ fieldset.description|safe }}</div>
    55    {% endif %}
    66    {% for line in fieldset %}
    7         <div class="form-row{% if line.errors %} errors{% endif %} {% for field in line %}{{ field.field.name }} {% endfor %} ">
     7        <div class="form-row{% if line.errors %} errors{% endif %}{% for field in line %} {% if field.is_readonly %}{{ field.field_name }}{% else %}{{ field.field.name }}{% endif %}{% endfor %}">
    88            {{ line.errors }}
    99            {% for field in line %}
    1010                <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>
  • tests/regressiontests/admin_views/tests.py

     
    19441944            formats.localize(datetime.date.today() - datetime.timedelta(days=7))
    19451945        )
    19461946
     1947        self.assertContains(response, '<div class="form-row coolness">')
     1948        self.assertContains(response, '<div class="form-row awesomeness_level">')
     1949        self.assertContains(response, '<div class="form-row posted">')
     1950        self.assertContains(response, '<div class="form-row ">')
     1951
    19471952        p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
    19481953        response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)
    19491954        self.assertContains(response, "%d amount of cool" % p.pk)
Back to Top