[Django] #19538: __admin_media_prefix__ in admin templates

35 views
Skip to first unread message

Django

unread,
Dec 29, 2012, 11:33:25 PM12/29/12
to django-...@googlegroups.com
#19538: __admin_media_prefix__ in admin templates
-------------------------------+-------------------------------
Reporter: andrew@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Keywords: admin S3 DateTime
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/19538>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 30, 2012, 7:08:27 AM12/30/12
to django-...@googlegroups.com
#19538: __admin_media_prefix__ in admin templates
-----------------------------------+--------------------------------------

Reporter: andrew@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:

Keywords: admin S3 DateTime | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by apollo13):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> 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.

New description:

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>
}}}

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:1>

Django

unread,
Dec 31, 2012, 2:27:48 PM12/31/12
to django-...@googlegroups.com
#19538: __admin_media_prefix__ in admin templates
-----------------------------------+------------------------------------
Reporter: andrew@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by aaugustin):

* type: Uncategorized => Bug
* component: Uncategorized => contrib.admin
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:2>

Django

unread,
Feb 24, 2013, 10:09:23 AM2/24/13
to django-...@googlegroups.com
#19538: __admin_media_prefix__ in admin templates
-----------------------------------+------------------------------------
Reporter: andrew@… | Owner: garanko
Type: Bug | Status: assigned

Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by garanko):

* status: new => assigned
* owner: nobody => garanko


--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:3>

Django

unread,
Nov 9, 2013, 11:34:07 AM11/9/13
to django-...@googlegroups.com
#19538: __admin_media_prefix__ in admin templates
-----------------------------------+------------------------------------
Reporter: andrew@… | Owner: garanko
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by claudep):

#21395 has been marked as a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:4>

Django

unread,
Dec 6, 2013, 7:02:17 PM12/6/13
to django-...@googlegroups.com
#19538: __admin_media_prefix__ in admin templates
-----------------------------------+------------------------------------
Reporter: andrew@… | Owner: garanko
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:5>

Django

unread,
Mar 4, 2015, 1:55:27 PM3/4/15
to django-...@googlegroups.com
#19538: Remove __admin_media_prefix__ in admin templates
-------------------------------------+-------------------------------------
Reporter: andrew@… | Owner: timgraham
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* version: 1.4 => master
* owner: garanko => timgraham
* needs_docs: 0 => 1
* has_patch: 0 => 1
* type: Bug => Cleanup/optimization


Comment:

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

[https://github.com/django/django/pull/4236 Work in progress]

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:6>

Django

unread,
Mar 4, 2015, 6:29:19 PM3/4/15
to django-...@googlegroups.com
#19538: Remove __admin_media_prefix__ in admin templates
-------------------------------------+-------------------------------------
Reporter: andrew@… | Owner: timgraham
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_docs: 1 => 0


Comment:

Addressed todos; ready for review now.

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:7>

Django

unread,
Mar 4, 2015, 7:52:04 PM3/4/15
to django-...@googlegroups.com
#19538: Remove __admin_media_prefix__ in admin templates
-------------------------------------+-------------------------------------
Reporter: andrew@… | Owner: timgraham
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin S3 DateTime | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by collinanderson):

* stage: Accepted => Ready for checkin


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:8>

Django

unread,
Mar 5, 2015, 7:09:04 AM3/5/15
to django-...@googlegroups.com
#19538: Remove __admin_media_prefix__ in admin templates
-------------------------------------+-------------------------------------
Reporter: andrew@… | Owner: timgraham
Type: | Status: closed

Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed

Keywords: admin S3 DateTime | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d61ebc8fed212366340b1ed6f5d7722613801459"]:
{{{
#!CommitTicketReference repository=""
revision="d61ebc8fed212366340b1ed6f5d7722613801459"
Fixed #19538 -- Removed window.__admin_media_prefix__ from admin
templates.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19538#comment:9>

Reply all
Reply to author
Forward
0 new messages