Opened 5 years ago

Closed 2 years ago

#13150 closed New feature (fixed)

Replace make_safe(media) with media in ModelAdmin context dictionary

Reported by: lsbardel Owned by: sergeykolosov
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 5 years ago.
widget.diff (1.1 KB) - added by lsbardel 5 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 5 years ago by russellm

  • Component changed from django.contrib.admin to Forms
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 5 years ago by lsbardel

True, small modification in forms/widget.py attached

Changed 5 years ago by lsbardel

Changed 5 years ago by lsbardel

comment:3 Changed 5 years ago by lsbardel

  • Owner changed from nobody to lsbardel
  • Status changed from new to assigned

comment:4 Changed 4 years ago by SmileyChris

  • Needs tests set
  • Patch needs improvement unset

comment:5 Changed 4 years ago by lukeplant

  • Type set to New feature

comment:6 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:7 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:8 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:9 Changed 2 years ago by sergeykolosov

  • Owner changed from lsbardel to sergeykolosov

comment:10 Changed 2 years ago by sergeykolosov

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

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