Ticket #14355: patch.5.with_test.diff

File patch.5.with_test.diff, 4.1 KB (added by wamberg, 14 years ago)

git diff patch for help_text on readonly fields

  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    index b90f5ec..6ca2941 100644
    a b  
    11from django import forms
    22from django.conf import settings
    33from django.contrib.admin.util import flatten_fieldsets, lookup_field
    4 from django.contrib.admin.util import display_for_field, label_for_field
     4from django.contrib.admin.util import display_for_field, label_for_field, help_text_for_field
    55from django.contrib.contenttypes.models import ContentType
    66from django.core.exceptions import ObjectDoesNotExist
    77from django.db.models.fields.related import ManyToManyRel
    class AdminReadonlyField(object):  
    140140            class_name = field.__name__ != '<lambda>' and field.__name__ or ''
    141141        else:
    142142            class_name = field
     143
    143144        self.field = {
    144145            'name': class_name,
    145146            'label': label,
    146147            'field': field,
     148                        'help_text': help_text_for_field(class_name, form._meta.model)
    147149        }
     150
    148151        self.form = form
    149152        self.model_admin = model_admin
    150153        self.is_first = is_first
    151154        self.is_checkbox = False
    152155        self.is_readonly = True
     156        self.help_text = help_text_for_field(class_name, form._meta.model)
    153157
    154158    def label_tag(self):
    155159        attrs = {}
  • django/contrib/admin/templates/admin/includes/fieldset.html

    diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html
    index addfd08..6363aee 100644
    a b  
    1919                            {{ field.field }}
    2020                        {% endif %}
    2121                    {% endif %}
    22                     {% if field.field.field.help_text %}
    23                         <p class="help">{{ field.field.field.help_text|safe }}</p>
     22                    {% if field.field.help_text %}
     23                        <p class="help">{{ field.field.help_text|safe }}</p>
    2424                    {% endif %}
    2525                </div>
    2626            {% endfor %}
  • django/contrib/admin/util.py

    diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
    index 1c39614..d3f17d6 100644
    a b def label_for_field(name, model, model_admin=None, return_attr=False):  
    266266    else:
    267267        return label
    268268
     269def help_text_for_field(name, model):
     270    try:
     271        help_text = model._meta.get_field_by_name(name)[0].help_text
     272    except models.FieldDoesNotExist:
     273        help_text = ""
     274    return smart_unicode(help_text)
     275
    269276
    270277def display_for_field(value, field):
    271278    from django.contrib.admin.templatetags.admin_list import _boolean_icon
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index e64f713..6c40cf4 100644
    a b class LinkInline(admin.TabularInline):  
    495495class Post(models.Model):
    496496    title = models.CharField(max_length=100)
    497497    content = models.TextField()
    498     posted = models.DateField(default=datetime.date.today)
     498    posted = models.DateField(
     499            default=datetime.date.today,
     500            help_text="Date post was posted and some unicode: ŠĐĆŽćžšđ"
     501    )
    499502    public = models.NullBooleanField()
    500503
    501504    def awesomeness_level(self):
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 661954c..13d1d13 100644
    a b class ReadonlyTest(TestCase):  
    23082308        self.assertContains(response, '<div class="form-row posted">')
    23092309        self.assertContains(response, '<div class="form-row value">')
    23102310        self.assertContains(response, '<div class="form-row ">')
     2311        self.assertContains(response, 'Date post was posted and some unicode: ŠĐĆŽćžšđ')
    23112312
    23122313        p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
    23132314        response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)
Back to Top