Opened 3 years ago

Closed 3 years ago

#17239 closed Cleanup/optimization (fixed)

mark_safe(media) in django admin Opzioni

Reported by: riccardodivirgilio Owned by: pbnan
Component: contrib.admin Version: master
Severity: Normal Keywords: mark_safe media
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

a minor bug in django admin.

in django.contrib.admin.options mark_safe is called to render media.
in add_view and change_view we can find mark_safe(media)

in changelist_view media is injected as an object (without mark_safe)
i propose to pass the media object to the template (without
mark_safe), because i use a template tag that adds media.

so i check in the context if there is 'media' key, and then merge my
own list of javascript and css with the existing django media.

but i cannot do this if the media object is rendered before it is
passed to the context processor.

Attachments (1)

remove_unnecessary_mark_safe_17239.diff (1012 bytes) - added by pbnan 3 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

Indeed:

  • changelist_view passes an instance of forms.Media in the context, and admin/change_list.html renders separately {{ media.css }} and {{ media.js }};
  • add_view and change_view passes a string, rendered as a side effect of calling mark_safe, and admin/change_form.html renders directly {{ media }}.

It could be worth to resolve this inconsistency, which appeared at r10077 and doesn't seem justified.

comment:2 Changed 3 years ago by pbnan

  • Owner changed from nobody to pbnan

Changed 3 years ago by pbnan

comment:3 Changed 3 years ago by pbnan

  • Has patch set

The change is harmless, as django.forms.widgets.Media is being "marked_safe" upon rendering in template.

comment:4 Changed 3 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 3 years ago by jezdez

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

In [17475]:

(The changeset message doesn't reference this ticket)

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