Fixed #25465 -- Restored line breaks conversion in admin readonly fields.
This commit is contained in:
parent
dbb0df2a0e
commit
69208a5a1c
|
@ -216,6 +216,7 @@ class AdminReadonlyField(object):
|
||||||
result_repr = ", ".join(map(six.text_type, value.all()))
|
result_repr = ", ".join(map(six.text_type, value.all()))
|
||||||
else:
|
else:
|
||||||
result_repr = display_for_field(value, f, self.empty_value_display)
|
result_repr = display_for_field(value, f, self.empty_value_display)
|
||||||
|
result_repr = linebreaksbr(result_repr)
|
||||||
return conditional_escape(result_repr)
|
return conditional_escape(result_repr)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,3 +48,6 @@ Bugfixes
|
||||||
``filter_horizontal`` and ``filter_vertical`` widgets, which could result
|
``filter_horizontal`` and ``filter_vertical`` widgets, which could result
|
||||||
in inadvertent data loss if a user didn't notice that and then submitted the
|
in inadvertent data loss if a user didn't notice that and then submitted the
|
||||||
form (:ticket:`22955`).
|
form (:ticket:`22955`).
|
||||||
|
|
||||||
|
* Fixed a regression in the admin which ignored line breaks in read-only fields
|
||||||
|
instead of converting them to ``<br>`` (:ticket:`25465`).
|
||||||
|
|
|
@ -67,3 +67,6 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed ``isnull`` query lookup for ``ForeignObject``
|
* Fixed ``isnull`` query lookup for ``ForeignObject``
|
||||||
(:ticket:`25972`).
|
(:ticket:`25972`).
|
||||||
|
|
||||||
|
* Fixed a regression in the admin which ignored line breaks in read-only fields
|
||||||
|
instead of converting them to ``<br>`` (:ticket:`25465`).
|
||||||
|
|
|
@ -387,7 +387,7 @@ class LinkInline(admin.TabularInline):
|
||||||
model = Link
|
model = Link
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
readonly_fields = ("posted", "multiline")
|
readonly_fields = ("posted", "multiline", "readonly_link_content")
|
||||||
|
|
||||||
def multiline(self, instance):
|
def multiline(self, instance):
|
||||||
return "InlineMultiline\ntest\nstring"
|
return "InlineMultiline\ntest\nstring"
|
||||||
|
@ -435,7 +435,7 @@ class PostAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = (
|
readonly_fields = (
|
||||||
'posted', 'awesomeness_level', 'coolness', 'value',
|
'posted', 'awesomeness_level', 'coolness', 'value',
|
||||||
'multiline', 'multiline_html', lambda obj: "foo",
|
'multiline', 'multiline_html', lambda obj: "foo",
|
||||||
'multiline_html_allow_tags',
|
'multiline_html_allow_tags', 'readonly_content',
|
||||||
)
|
)
|
||||||
|
|
||||||
inlines = [
|
inlines = [
|
||||||
|
|
|
@ -451,6 +451,7 @@ class Link(models.Model):
|
||||||
posted = models.DateField(default=link_posted_default)
|
posted = models.DateField(default=link_posted_default)
|
||||||
url = models.URLField()
|
url = models.URLField()
|
||||||
post = models.ForeignKey("Post", models.CASCADE)
|
post = models.ForeignKey("Post", models.CASCADE)
|
||||||
|
readonly_link_content = models.TextField()
|
||||||
|
|
||||||
|
|
||||||
class PrePopulatedPost(models.Model):
|
class PrePopulatedPost(models.Model):
|
||||||
|
@ -468,6 +469,7 @@ class PrePopulatedSubPost(models.Model):
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
|
title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
|
||||||
content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
|
content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
|
||||||
|
readonly_content = models.TextField()
|
||||||
posted = models.DateField(
|
posted = models.DateField(
|
||||||
default=datetime.date.today,
|
default=datetime.date.today,
|
||||||
help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
|
help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
|
||||||
|
|
|
@ -50,7 +50,7 @@ from .models import (
|
||||||
City, Collector, Color, ComplexSortedPerson, CoverLetter, CustomArticle,
|
City, Collector, Color, ComplexSortedPerson, CoverLetter, CustomArticle,
|
||||||
CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel, ExternalSubscriber,
|
CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel, ExternalSubscriber,
|
||||||
Fabric, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount,
|
Fabric, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount,
|
||||||
FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language,
|
FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language, Link,
|
||||||
MainPrepopulated, ModelWithStringPrimaryKey, OtherStory, Paper, Parent,
|
MainPrepopulated, ModelWithStringPrimaryKey, OtherStory, Paper, Parent,
|
||||||
ParentWithDependentChildren, Person, Persona, Picture, Pizza, Plot,
|
ParentWithDependentChildren, Person, Persona, Picture, Pizza, Plot,
|
||||||
PlotDetails, PluggableSearchPerson, Podcast, Post, PrePopulatedPost, Promo,
|
PlotDetails, PluggableSearchPerson, Podcast, Post, PrePopulatedPost, Promo,
|
||||||
|
@ -4581,6 +4581,22 @@ class ReadonlyTest(TestCase):
|
||||||
response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,)))
|
response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,)))
|
||||||
self.assertContains(response, "%d amount of cool" % p.pk)
|
self.assertContains(response, "%d amount of cool" % p.pk)
|
||||||
|
|
||||||
|
@ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation
|
||||||
|
def test_readonly_text_field(self):
|
||||||
|
p = Post.objects.create(
|
||||||
|
title="Readonly test", content="test",
|
||||||
|
readonly_content='test\r\n\r\ntest\r\n\r\ntest\r\n\r\ntest',
|
||||||
|
)
|
||||||
|
Link.objects.create(
|
||||||
|
url="http://www.djangoproject.com", post=p,
|
||||||
|
readonly_link_content="test\r\nlink",
|
||||||
|
)
|
||||||
|
response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,)))
|
||||||
|
# Checking readonly field.
|
||||||
|
self.assertContains(response, 'test<br /><br />test<br /><br />test<br /><br />test')
|
||||||
|
# Checking readonly field in inline.
|
||||||
|
self.assertContains(response, 'test<br />link')
|
||||||
|
|
||||||
def test_readonly_post(self):
|
def test_readonly_post(self):
|
||||||
data = {
|
data = {
|
||||||
"title": "Django Got Readonly Fields",
|
"title": "Django Got Readonly Fields",
|
||||||
|
|
Loading…
Reference in New Issue