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
|
| 7 | 7 | from django.core.exceptions import ObjectDoesNotExist |
| 8 | 8 | from django.db.models.fields.related import ManyToManyRel |
| 9 | 9 | from django.forms.utils import flatatt |
| 10 | | from django.template.defaultfilters import capfirst |
| | 10 | from django.template.defaultfilters import capfirst, linebreaksbr |
| 11 | 11 | from django.utils.encoding import force_text, smart_text |
| 12 | 12 | from django.utils.html import conditional_escape, format_html |
| 13 | 13 | from django.utils.safestring import mark_safe |
| … |
… |
class AdminReadonlyField(object):
|
| 182 | 182 | result_repr = smart_text(value) |
| 183 | 183 | if getattr(attr, "allow_tags", False): |
| 184 | 184 | result_repr = mark_safe(result_repr) |
| | 185 | else: |
| | 186 | result_repr = linebreaksbr(result_repr) |
| 185 | 187 | else: |
| 186 | 188 | if isinstance(f.rel, ManyToManyRel) and value is not None: |
| 187 | 189 | result_repr = ", ".join(map(six.text_type, value.all())) |
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
|
|
| 47 | 47 | {% if not field.field.is_hidden %} |
| 48 | 48 | <td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}> |
| 49 | 49 | {% if field.is_readonly %} |
| 50 | | <p>{{ field.contents|linebreaksbr }}</p> |
| | 50 | <p>{{ field.contents }}</p> |
| 51 | 51 | {% else %} |
| 52 | 52 | {{ field.field.errors.as_ul }} |
| 53 | 53 | {{ field.field }} |
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
|
|
| 14 | 14 | {% else %} |
| 15 | 15 | {{ field.label_tag }} |
| 16 | 16 | {% if field.is_readonly %} |
| 17 | | <p>{{ field.contents|linebreaksbr }}</p> |
| | 17 | <p>{{ field.contents }}</p> |
| 18 | 18 | {% else %} |
| 19 | 19 | {{ field.field }} |
| 20 | 20 | {% endif %} |
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
|
| 15 | 15 | from django.forms.models import BaseModelFormSet |
| 16 | 16 | from django.http import HttpResponse, StreamingHttpResponse |
| 17 | 17 | from django.contrib.admin import BooleanFieldListFilter |
| | 18 | from django.utils.safestring import mark_safe |
| 18 | 19 | from django.utils.six import StringIO |
| 19 | 20 | |
| 20 | 21 | from .models import (Article, Chapter, Child, Parent, Picture, Widget, |
| … |
… |
class PrePopulatedPostAdmin(admin.ModelAdmin):
|
| 407 | 408 | class PostAdmin(admin.ModelAdmin): |
| 408 | 409 | list_display = ['title', 'public'] |
| 409 | 410 | 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" |
| 412 | 413 | ) |
| 413 | 414 | |
| 414 | 415 | inlines = [ |
| … |
… |
class PostAdmin(admin.ModelAdmin):
|
| 427 | 428 | def multiline(self, instance): |
| 428 | 429 | return "Multiline\ntest\nstring" |
| 429 | 430 | |
| | 431 | def multiline_html(self, instance): |
| | 432 | return mark_safe("Multiline<br>\nhtml<br>\ncontent") |
| | 433 | multiline_html.allow_tags = True |
| | 434 | |
| 430 | 435 | value.short_description = 'Value in $US' |
| 431 | 436 | |
| 432 | 437 | |
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index c39e99a..a88117f 100644
|
a
|
b
|
class ReadonlyTest(TestCase):
|
| 3622 | 3622 | |
| 3623 | 3623 | # Checks that multiline text in a readonly field gets <br /> tags |
| 3624 | 3624 | self.assertContains(response, "Multiline<br />test<br />string") |
| | 3625 | self.assertContains(response, "<p>Multiline<br />html<br />content</p>", html=True) |
| 3625 | 3626 | self.assertContains(response, "InlineMultiline<br />test<br />string") |
| 3626 | 3627 | |
| 3627 | 3628 | self.assertContains(response, |