Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13445 closed (invalid)

Problem with DateTimeShortcuts.admin_media_prefix

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

Description

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);
                break;
            }
        }

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 by anonymous, 14 years ago

Version: 1.11.2-beta

comment:2 by anonymous, 14 years ago

milestone: 1.2

comment:3 by Ramiro Morales, 14 years ago

Component: Uncategorizeddjango.contrib.admin
Resolution: invalid
Status: newclosed
Version: 1.2-betaSVN

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 by Ramiro Morales, 14 years ago

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

comment:5 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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