Opened 7 years ago

Closed 4 years ago

#13150 closed New feature (fixed)

Replace make_safe(media) with media in ModelAdmin context dictionary

Reported by: lsbardel Owned by: Sergey Kolosov
Component: Forms Version: master
Severity: Normal Keywords: media
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, the media object is converted to safe string in both add_view and change_view methods when added to the context dictionary
while in changelist_view is not (the correct approach).
Converting media to string means you cannot split css from js in
templates. What I'd like to do is

<head> 
... 
{% for css in media.render_css %} 
{{ css|safe }}{% endfor %} 
</head> 
<body> 
... 
{% for js in media.render_js %} 
{{ js|safe }}{% endfor %} 
</body>


A two lines modification.

Attachments (2)

options.diff (1002 bytes) - added by lsbardel 7 years ago.
widget.diff (1.1 KB) - added by lsbardel 7 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by Russell Keith-Magee

Component: django.contrib.adminForms
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Valid point (and fix), but you shouldn't need to do the |safe yourself. Django is generating the HTML; it should be considered safe. The contents of render_css and render_js should be marked safe internally ready for rendering.

comment:2 Changed 7 years ago by lsbardel

True, small modification in forms/widget.py attached

Changed 7 years ago by lsbardel

Attachment: options.diff added

Changed 7 years ago by lsbardel

Attachment: widget.diff added

comment:3 Changed 7 years ago by lsbardel

Owner: changed from nobody to lsbardel
Status: newassigned

comment:4 Changed 6 years ago by Chris Beaven

Needs tests: set
Patch needs improvement: unset

comment:5 Changed 6 years ago by Luke Plant

Type: New feature

comment:6 Changed 6 years ago by Luke Plant

Severity: Normal

comment:7 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 Changed 4 years ago by Sergey Kolosov

Owner: changed from lsbardel to Sergey Kolosov

comment:10 Changed 4 years ago by Sergey Kolosov

Resolution: fixed
Status: assignedclosed

It had been already fixed a while ago:
https://github.com/django/django/commit/a92e7f37c4ae84b6b8d8016cc6783211e9047219

The patch above is not needed anymore.

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