Opened 12 years ago

Closed 10 years ago

#19538 closed Cleanup/optimization (fixed)

Remove __admin_media_prefix__ in admin templates

Reported by: andrew@… Owned by: Tim Graham
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin S3 DateTime
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 (last modified by Florian Apolloner)

contrib/admin/templates/admin/base.html contains the line:

<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% static "admin/" %}{% endfilter %}";</script>

The __admin_media_prefix__ is used in contrib/admin/static/admin/js/admin/DateTimeShortcuts.js to form URLs by concatenation:
DateTimeShortcuts.admin_media_prefix + 'img/icon_clock.gif'

This causes a problem with certain storage backends (such as S3 Boto) which include authentication digests as part of the URL. For instance, when using the S3 Boto backend, my admin renders the following line:

<script type="text/javascript">window.__admin_media_prefix__ = "https://oca3\u002Dqa.s3.amazonaws.com/admin?Signature\u003DXIt%2FCc9wPWjaw%2F3ITNjkYE3bc%2FI%3D\u0026Expires\u003D1356844210\u0026AWSAccessKeyId\u003DAKIAIGREZ7J53KZ23QKQ";</script>

Which, when concatenated with the fixed string generates the invalid URL: https://oca3\u002Dqa.s3.amazonaws.com/admin?Signature\u003DXIt%2FCc9wPWjaw%2F3ITNjkYE3bc%2FI%3D\u0026Expires\u003D1356844210\u0026AWSAccessKeyId\u003DAKIAIGREZ7J53KZ23QKQimg/icon_clock.gif

I suspect that the assumption the DateTime widget is relying on ({% static a+b %} should be equivelant to {% static a %}b) is invalid, and it should be using a more robust method to determine the static URL of its resources. The DateTime widget appears to be the only element depending on __admin_media_prefix__, and thus the only one to fail when switching to a backend that doesn't support its assumption.

Change History (9)

comment:1 by Florian Apolloner, 12 years ago

Description: modified (diff)

comment:2 by Aymeric Augustin, 12 years ago

Component: Uncategorizedcontrib.admin
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 by garanko, 12 years ago

Owner: changed from nobody to garanko
Status: newassigned

comment:4 by Claude Paroz, 11 years ago

#21395 has been marked as a duplicate.

comment:5 by wraus@…, 11 years ago

Has there been any progress on this? This is causing some issues for me, since I'm looking to switch over to S3. Technically everything still works, but there shouldn't be broken images in the admin just because I want to use S3.

comment:6 by Tim Graham, 10 years ago

Has patch: set
Needs documentation: set
Owner: changed from garanko to Tim Graham
Summary: __admin_media_prefix__ in admin templatesRemove __admin_media_prefix__ in admin templates
Type: BugCleanup/optimization
Version: 1.4master

We can address this by moving image references to CSS and using relative paths.

Work in progress

comment:7 by Tim Graham, 10 years ago

Needs documentation: unset

Addressed todos; ready for review now.

comment:8 by Collin Anderson, 10 years ago

Triage Stage: AcceptedReady for checkin

I don't want to rush it, but the PR looks good.

comment:9 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In d61ebc8fed212366340b1ed6f5d7722613801459:

Fixed #19538 -- Removed window.admin_media_prefix from admin templates.

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