Ticket #22241: 22241-1.diff

File 22241-1.diff, 4.4 KB (added by Claude Paroz, 11 years ago)

Initial patch to fix this issue

  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    index 50d0892..bf80ac5 100644
    a b from django.contrib.admin.templatetags.admin_static import static  
    77from django.core.exceptions import ObjectDoesNotExist
    88from django.db.models.fields.related import ManyToManyRel
    99from django.forms.utils import flatatt
    10 from django.template.defaultfilters import capfirst
     10from django.template.defaultfilters import capfirst, linebreaksbr
    1111from django.utils.encoding import force_text, smart_text
    1212from django.utils.html import conditional_escape, format_html
    1313from django.utils.safestring import mark_safe
    class AdminReadonlyField(object):  
    182182                    result_repr = smart_text(value)
    183183                    if getattr(attr, "allow_tags", False):
    184184                        result_repr = mark_safe(result_repr)
     185                    else:
     186                        result_repr = linebreaksbr(result_repr)
    185187            else:
    186188                if isinstance(f.rel, ManyToManyRel) and value is not None:
    187189                    result_repr = ", ".join(map(six.text_type, value.all()))
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
    index 2a34632..9ef6e8f 100644
    a b  
    4747              {% if not field.field.is_hidden %}
    4848              <td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
    4949              {% if field.is_readonly %}
    50                   <p>{{ field.contents|linebreaksbr }}</p>
     50                  <p>{{ field.contents }}</p>
    5151              {% else %}
    5252                  {{ field.field.errors.as_ul }}
    5353                  {{ field.field }}
  • 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 f38564c..c45e731 100644
    a b  
    1414                    {% else %}
    1515                        {{ field.label_tag }}
    1616                        {% if field.is_readonly %}
    17                             <p>{{ field.contents|linebreaksbr }}</p>
     17                            <p>{{ field.contents }}</p>
    1818                        {% else %}
    1919                            {{ field.field }}
    2020                        {% endif %}
  • tests/admin_views/admin.py

    diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
    index e9c6d4d..a392daf 100644
    a b from django.conf.urls import patterns, url  
    1515from django.forms.models import BaseModelFormSet
    1616from django.http import HttpResponse, StreamingHttpResponse
    1717from django.contrib.admin import BooleanFieldListFilter
     18from django.utils.safestring import mark_safe
    1819from django.utils.six import StringIO
    1920
    2021from .models import (Article, Chapter, Child, Parent, Picture, Widget,
    class PrePopulatedPostAdmin(admin.ModelAdmin):  
    407408class PostAdmin(admin.ModelAdmin):
    408409    list_display = ['title', 'public']
    409410    readonly_fields = (
    410         'posted', 'awesomeness_level', 'coolness', 'value', 'multiline',
    411         lambda obj: "foo"
     411        'posted', 'awesomeness_level', 'coolness', 'value',
     412        'multiline', 'multiline_html', lambda obj: "foo"
    412413    )
    413414
    414415    inlines = [
    class PostAdmin(admin.ModelAdmin):  
    427428    def multiline(self, instance):
    428429        return "Multiline\ntest\nstring"
    429430
     431    def multiline_html(self, instance):
     432        return mark_safe("Multiline<br>\nhtml<br>\ncontent")
     433    multiline_html.allow_tags = True
     434
    430435    value.short_description = 'Value in $US'
    431436
    432437
  • tests/admin_views/tests.py

    diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
    index c39e99a..a88117f 100644
    a b class ReadonlyTest(TestCase):  
    36223622
    36233623        # Checks that multiline text in a readonly field gets <br /> tags
    36243624        self.assertContains(response, "Multiline<br />test<br />string")
     3625        self.assertContains(response, "<p>Multiline<br />html<br />content</p>", html=True)
    36253626        self.assertContains(response, "InlineMultiline<br />test<br />string")
    36263627
    36273628        self.assertContains(response,
Back to Top