Ticket #14355: 14355_readonly_fields_help_text.diff

File 14355_readonly_fields_help_text.diff, 4.3 KB (added by Julien Phalip, 14 years ago)
  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    index b90f5ec..3c1bef3 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):  
    144144            'name': class_name,
    145145            'label': label,
    146146            'field': field,
     147            'help_text': help_text_for_field(class_name, form._meta.model)
    147148        }
    148149        self.form = form
    149150        self.model_admin = model_admin
  • 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 60319ea..c344a14 100644
    a b class LinkInline(admin.TabularInline):  
    523523
    524524
    525525class Post(models.Model):
    526     title = models.CharField(max_length=100)
    527     content = models.TextField()
    528     posted = models.DateField(default=datetime.date.today)
     526    title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
     527    content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
     528    posted = models.DateField(
     529            default=datetime.date.today,
     530            help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
     531    )
    529532    public = models.NullBooleanField()
    530533
    531534    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 acbbbfc..e4644e1 100644
    a b class ReadonlyTest(TestCase):  
    23922392        self.assertContains(response, '<div class="form-row posted">')
    23932393        self.assertContains(response, '<div class="form-row value">')
    23942394        self.assertContains(response, '<div class="form-row ">')
     2395        self.assertContains(response, '<p class="help">', 3)
     2396        self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>')
     2397        self.assertContains(response, '<p class="help">Some help text for the content (with unicode ŠĐĆŽćžšđ)</p>')
     2398        self.assertContains(response, '<p class="help">Some help text for the date (with unicode ŠĐĆŽćžšđ)</p>')
    23952399
    23962400        p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
    23972401        response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)
Back to Top