Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#19226 closed Bug (fixed)

Admin readonly fields ignore newlines

Reported by: shadow Owned by: Lebedev Ilya
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: atodorov@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

A TextField that is marked as readonly in the Admin will be displayed in a simple <p>, effectively removing any newlines that were entered. Since in HTML, <textarea> displays newlines as you enter them, it would be more appropriate if <pre> were used to display the data when it is readonly.

See: contrib/admin/templates/admin/includes/fieldset.html:17

thanks

Attachments (4)

ticket_19226.diff (693 bytes ) - added by Lebedev Ilya 11 years ago.
ticket_19226.2.diff (1.8 KB ) - added by Lebedev Ilya 11 years ago.
ticket_19226.3.diff (2.7 KB ) - added by Lebedev Ilya 11 years ago.
ticket_19226.4.diff (2.2 KB ) - added by thiderman 11 years ago.
Patch with tests for br tags

Download all attachments as: .zip

Change History (21)

comment:1 by shadow, 11 years ago

A nicer solution (rather than <pre>) might be:

<p>{{ field.contents|linebreaksbr }}</p>

As this avoids the other styling that goes along with <pre>

comment:2 by Claude Paroz, 11 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Lebedev Ilya, 11 years ago

Owner: changed from nobody to Lebedev Ilya

by Lebedev Ilya, 11 years ago

Attachment: ticket_19226.diff added

comment:4 by Lebedev Ilya, 11 years ago

Has patch: set

comment:5 by Lebedev Ilya, 11 years ago

Status: newassigned

comment:6 by Claude Paroz, 11 years ago

Needs tests: set

I think you could tweak the existing test_readonly_get in admin_views tests to include a new line in some value.

by Lebedev Ilya, 11 years ago

Attachment: ticket_19226.2.diff added

comment:7 by Lebedev Ilya, 11 years ago

Needs tests: unset

comment:8 by Claude Paroz, 11 years ago

You are near, but you have tested a non-readonly field, otherwise the test would have failed (as you should get <br> instead of newlines).

by Lebedev Ilya, 11 years ago

Attachment: ticket_19226.3.diff added

by thiderman, 11 years ago

Attachment: ticket_19226.4.diff added

Patch with tests for br tags

comment:9 by thiderman, 11 years ago

I fixed the last patch so that it actually executes and added an assertion that the conversion into <br /> tags was actually made.

comment:10 by Jannis Leidel, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Claude Paroz <claude@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In ec9d6b1122dd09168d8b2dbcabc745f22f0ef766:

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

Thanks shadow for the report, and Melevir and thiderman for the
patch.

comment:12 by Claude Paroz <claude@…>, 11 years ago

In 1b6e751430b6c151079f616ec5d4f8f3446ea24e:

[1.5.x] Fixed #19226 -- Applied linebreaksbr to read-only fields in admin

Thanks shadow for the report, and Melevir and thiderman for the
patch.
Backport of ec9d6b112 from master.

comment:13 by anonymous, 11 years ago

Yep guys,
I've found that this is not fixed for inlines. I've opened this ticket: #19429

comment:14 by atodorov@…, 10 years ago

Resolution: fixed
Status: closednew

Hi guys,
this fix is breaking up display for me. I'm using computed read-only fields which display rich HTML into the model change form as a way to augment the administration experience which works really well for me.

Adding multiple line break tags breaks my display (this only happens because the templates used to render the fields have new lines in them). Now I have to go all-over my code and strip new lines before returning the field value.

It would be nice if the linebreaks filter skipped \n, <br/> replacement on safe strings.

comment:15 by atodorov@…, 10 years ago

Cc: atodorov@… added

comment:16 by Claude Paroz, 10 years ago

Resolution: fixed
Status: newclosed

Hi, could you please open a new ticket (referencing this one) with your use case instead of reopening a rather old ticket? And it would probably help understanding of your issue if you can provide some code example, maybe even screenshots.

Note: See TracTickets for help on using tickets.
Back to Top