Opened 17 years ago

Closed 16 years ago

Last modified 13 years ago

#7129 closed (fixed)

Prepend of admin_media is not working on JS

Reported by: Anderson Santos Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-blocker
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When declaring an admin class when I declare in the inner class Media the js list of scripts with relative url, it should prepend the admin_media url but it is not working for me:

eg:

class MyClass(admin.ModelAdmin):
    list_filter = ('created','published_date','section','journalist')
    search_fields = ('headline','story')
    
    class Media:
        js = ['/mymedia/js/MyScript.js',
              'js/getElementsBySelector.js'] #it should be relative to media, but it has default media instead

This is what documentation says about JS section

"If you use relative URLs — URLs that don’t start with http:// or / — then the admin site will automatically prefix these links with settings.ADMIN_MEDIA_PREFIX"

Change History (10)

comment:1 by Brian Rosner, 17 years ago

Can you provide a bit more information? What is the value of both MEDIA_URL and ADMIN_MEDIA_PREFIX? Also what is the exact output of the URL?

comment:2 by Anderson Santos, 17 years ago

ok, so I have the following configuration

MEDIA_URL = '/local_media/'

ADMIN_MEDIA_PREFIX = '/media/admin/'

and the following model representation for admin:

class MyClass(admin.ModelAdmin):

list_filter = ('field',)
search_fields = ('field',)


class Media:

js = ['/mymedia/js/i_am_in_any_media.js',

'js/i_am_in_admin.js']

Usign trunk, the first js will keep untouched which is fine on both but the second one on trunk will become "/media/admin/js/i_am_in_admin.js", but usign newsforms-admin it returns the same "js/i_amin_in_admin.js" with nothing prefixed. Since the django docs says that the ADMIN_MEDIA_PREFIX will prepend relative urls, I consider this should be the same for newforms-admin

comment:3 by Karen Tracey <kmtracey@…>, 16 years ago

Keywords: nfa-blocker added

Adding the ADMIN_MEDIA_PREFIX used to be done by the include_admin_script templatetag. This seems to be gone in nfa and it doesn't seem the code has been added anywhere to check for relative/absolute user-specified js and add ADMIN_MEDIA_PREFIX if necessary. Marking nfa-blocker since it's a regression from trunk.

comment:4 by Brian Rosner, 16 years ago

Resolution: invalid
Status: newclosed

Ok, I looked into this. It appears the reporter was reading the wrong documentation. The old js inner Admin class used to do this. The correct way to use ADMIN_MEDIA_PREFIX is to add it explicitly similar to how it is done here http://code.djangoproject.com/browser/django/branches/newforms-admin/django/contrib/admin/options.py#L272. It is a good thing it defaults to MEDIA_URL since that is the only place you should be adding your own CSS/JS. If you are needing to include something from ADMIN_MEDIA_PREFIX then there is another bug.

comment:5 by Karen Tracey <kmtracey@…>, 16 years ago

I'm confused. This is the doc referenced by the original submitter:

http://www.djangoproject.com/documentation/model-api/#js

Sure, that's for old admin but I don't see any reference either here:

http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowdoIaddcustomJavaScriptCSS

or here:

http://code.djangoproject.com/wiki/NewformsAdminBranch

to the "new" way requiring that the specified js be fully-qualified.

That text has been pulled from the newforms-admin version of that doc file (the entire description of specifying js, not just the bit about what happens if it's not fully-qualified), and I can't find anyplace it's been moved to, so it's a little hard to figure out how one is supposed to migrate this bit.

Are you saying it is bad practice to add your own js in amongst the Django-supplied files and therefore this implicit support for this has been dropped in newforms-admin? If so it seems at a minimum some doc is needed somewhere to clarify that, since a straightforward migration of some old working configs apparently won't work.

comment:6 by Brian Rosner, 16 years ago

Resolution: invalid
Status: closedreopened

Ok, I see where you are coming from. I will bring this up on django-dev mailing list to find out the original intensions and see if anything needs to be changed. I will reopen for now since it does seem like it will need to be addressed somehow.

comment:8 by Marc Garcia, 16 years ago

milestone: 1.0 alpha

comment:9 by Brian Rosner, 16 years ago

Resolution: fixed
Status: reopenedclosed

Ugh, Trac's post-commit hook failed again apparently. This was fixed in [7873]. I have also added a note to the http://code.djangoproject.com/wiki/NewformsAdminBranch page indicating the backward incompatibility with settings.ADMIN_MEDIA_PREFIX.

comment:10 by Jacob, 13 years ago

milestone: 1.0 alpha

Milestone 1.0 alpha deleted

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