Opened 13 years ago

Closed 13 years ago

#17239 closed Cleanup/optimization (fixed)

mark_safe(media) in django admin Opzioni

Reported by: Riccardo Di Virgilio Owned by: Piotr Banaszkiewicz
Component: contrib.admin Version: dev
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 Piotr Banaszkiewicz 13 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/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 by Piotr Banaszkiewicz, 13 years ago

Owner: changed from nobody to Piotr Banaszkiewicz

by Piotr Banaszkiewicz, 13 years ago

comment:3 by Piotr Banaszkiewicz, 13 years ago

Has patch: set

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

comment:4 by Jannis Leidel, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [17475]:

Fixed #17239 -- Stopped an inconsitent and unneeded use of mark_safe in the ModelAdmin. Thanks, pbnan.

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