Code

Opened 16 months ago

Last modified 4 months ago

#19538 assigned Bug

__admin_media_prefix__ in admin templates

Reported by: andrew@… Owned by: garanko
Component: contrib.admin Version: 1.4
Severity: Normal Keywords: admin S3 DateTime
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by apollo13)

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.

Attachments (0)

Change History (5)

comment:1 Changed 16 months ago by apollo13

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 16 months ago by aaugustin

  • Component changed from Uncategorized to contrib.admin
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

comment:3 Changed 14 months ago by garanko

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

comment:4 Changed 5 months ago by claudep

#21395 has been marked as a duplicate.

comment:5 Changed 4 months ago by wraus@…

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from garanko to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.