Opened 14 years ago
Closed 14 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)
Change History (6)
comment:1 by , 14 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → Cleanup/optimization |
comment:2 by , 14 years ago
| Owner: | changed from to |
|---|
by , 14 years ago
| Attachment: | remove_unnecessary_mark_safe_17239.diff added |
|---|
comment:3 by , 14 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 , 14 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Indeed:
changelist_viewpasses an instance offorms.Mediain the context, andadmin/change_list.htmlrenders separately{{ media.css }}and{{ media.js }};add_viewandchange_viewpasses a string, rendered as a side effect of callingmark_safe, andadmin/change_form.htmlrenders directly{{ media }}.It could be worth to resolve this inconsistency, which appeared at r10077 and doesn't seem justified.