Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#22241 closed Bug (fixed)

Extra line break tags in contrib/admin/templates/admin/includes/fieldset.html break display of computed fields

Reported by: atodorov@… Owned by: nobody
Component: contrib.admin Version: 1.6
Severity: Normal Keywords:
Cc: atodorov@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is a reference to #19226 which is not properly fixed.

See:
https://code.djangoproject.com/ticket/19226#comment:14

<quote>
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.
</quote>

Attached is code to reproduce. Run it on Django 1.4.X and then on 1.5.X or 1.6.X to see the difference.

In the add/change form for Advisory objects there are several divs which should appear on the same line but with the added line breaks they get messed up.

Workaround is to remove all newlines before rendering this field value.

Initially the bug was reported against text area type of fields so either fix it only for them or allow linebreaksbr filter to skip safe strings.

Attachments (4)

bugtest.tar.gz (1.8 KB) - added by atodorov@… 14 months ago.
Small project to reproduce the issue
django_1.4.png (22.3 KB) - added by atodorov@… 14 months ago.
Screenshot with Django 1.4.X
django_1.6.png (25.2 KB) - added by atodorov@… 14 months ago.
Screenshot with Django 1.6.X
22241-1.diff (4.4 KB) - added by claudep 14 months ago.
Initial patch to fix this issue

Download all attachments as: .zip

Change History (7)

Changed 14 months ago by atodorov@…

Small project to reproduce the issue

Changed 14 months ago by atodorov@…

Screenshot with Django 1.4.X

Changed 14 months ago by atodorov@…

Screenshot with Django 1.6.X

comment:1 Changed 14 months ago by claudep

  • Component changed from Template system to contrib.admin
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Thanks for the code and screenshots, this is helpful.

I'll upload a patch for this issue. Please review/test.

Changed 14 months ago by claudep

Initial patch to fix this issue

comment:2 Changed 14 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In c94bff2b26f8844fe15d68a79511ff3a6853dc61:

Fixed #22241 -- Selectively added line breaks in admin read-only fields

When content is supposed to contain HTML, we do not try to add
line breaks in read-only contents.
Thanks Alexander Todorov for the report.

comment:3 Changed 14 months ago by Claude Paroz <claude@…>

In d345a030c2f3b332512e5091248dd8b06e859eac:

[1.7.x] Fixed #22241 -- Selectively added line breaks in admin read-only fields

When content is supposed to contain HTML, we do not try to add
line breaks in read-only contents.
Thanks Alexander Todorov for the report.
Backport of c94bff2 from master.

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