Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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:

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

Attachments (0)

Change History (5)

comment:1 Changed 4 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 4 years ago by anonymous

  • milestone set to 1.2

comment:3 Changed 4 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 4 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 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


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

 
Note: See TracTickets for help on using tickets.