Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13445 closed (invalid)

Problem with DateTimeShortcuts.admin_media_prefix

Reported by: vaxXxa Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I use

from django.contrib.admin import widgets

class OrderForm(forms.ModelForm):
    class Meta:
        model = Order
        widgets = {
            'delivery_time_start': widgets.AdminSplitDateTime(),
            'delivery_time_end': widgets.AdminSplitDateTime(),

In \django\contrib\admin\media\js\admin\DateTimeShortcuts.js:

Was (Django 1.2 Beta 1):

// Deduce admin_media_prefix by looking at the <script>s in the
        // current document and finding the URL of *this* module.
        var scripts = document.getElementsByTagName('script');
        for (var i=0; i<scripts.length; i++) {
            if (scripts[i].src.match(/DateTimeShortcuts/)) {
                var idx = scripts[i].src.indexOf('js/admin/DateTimeShortcuts');
                DateTimeShortcuts.admin_media_prefix = scripts[i].src.substring(0, idx);

Now (Django 1.2 trunk (revision 13040)):

// Get admin_media_prefix by grabbing it off the window object. It's
        // set in the admin/base.html template, so if it's not there, someone's
        // overridden the template. In that case, we'll set a clearly-invalid
        // value in the hopes that someone will examine HTTP requests and see it.
        if (window.__admin_media_prefix__ != undefined) {
            DateTimeShortcuts.admin_media_prefix = window.__admin_media_prefix__;
        } else {
            DateTimeShortcuts.admin_media_prefix = '/missing-admin-media-prefix/';

So, if I use widgets.AdminSplitDateTime() in my forms I can't see image like 'img/admin/icon_clock.gif' and 'img/admin/icon_calendar.gif'.

Change History (5)

comment:1 Changed 5 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.1 to 1.2-beta

comment:2 Changed 5 years ago by anonymous

  • milestone set to 1.2

comment:3 Changed 5 years ago by ramiro

  • Component changed from Uncategorized to django.contrib.admin
  • Resolution set to invalid
  • Status changed from new to closed
  • Version changed from 1.2-beta to SVN

If you are the admin app widgets in your own app templates the you need to re-create as used by such app the same environment when rendering you it.

See [13002] for details. I suspect you need to add something like:

{% load adminmedia %}
<script type="text/javascript">window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";</script>

to you template to to every template where you render such a form (or to a common template up in the inheritance hierarchy).

I'm closing this ticket. Reopen if I've missed anything.

comment:4 Changed 5 years ago by ramiro

I meant "then you need to re-create the same environment as used by such app when rendering it. "

comment:5 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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