Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19226 -- Applied linebreaksbr to read-only fields in admin

Thanks shadow for the report, and Melevir and thiderman for the
patch.
  • Loading branch information...
commit ec9d6b1122dd09168d8b2dbcabc745f22f0ef766 1 parent 8c69278
@claudep claudep authored
View
2  django/contrib/admin/templates/admin/includes/fieldset.html
@@ -14,7 +14,7 @@
{% else %}
{{ field.label_tag }}
{% if field.is_readonly %}
- <p>{{ field.contents }}</p>
+ <p>{{ field.contents|linebreaksbr }}</p>
{% else %}
{{ field.field }}
{% endif %}
View
9 tests/regressiontests/admin_views/admin.py
@@ -388,7 +388,10 @@ def get_prepopulated_fields(self, request, obj=None):
class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'public']
- readonly_fields = ('posted', 'awesomeness_level', 'coolness', 'value', lambda obj: "foo")
+ readonly_fields = (
+ 'posted', 'awesomeness_level', 'coolness', 'value', 'multiline',
+ lambda obj: "foo"
+ )
inlines = [
LinkInline
@@ -402,6 +405,10 @@ def coolness(self, instance):
def value(self, instance):
return 1000
+
+ def multiline(self, instance):
+ return "Multiline\ntest\nstring"
+
value.short_description = 'Value in $US'
View
4 tests/regressiontests/admin_views/tests.py
@@ -3149,6 +3149,10 @@ def test_readonly_get(self):
self.assertContains(response, "Very awesome.")
self.assertContains(response, "Unkown coolness.")
self.assertContains(response, "foo")
+
+ # Checks that multiline text in a readonly field gets <br /> tags
+ self.assertContains(response, "Multiline<br />test<br />string")
+
self.assertContains(response,
formats.localize(datetime.date.today() - datetime.timedelta(days=7))
)
Please sign in to comment.
Something went wrong with that request. Please try again.