#12879 closed (fixed)
jquery gets included multiple times
Reported by: | mariarchi | Owned by: | Tobias McNulty |
---|---|---|---|
Component: | contrib.admin | Version: | 1.2-beta |
Severity: | Keywords: | jquery | |
Cc: | admin@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
ModelAdmin adds jquery.min.js to the self.media if self.actions is not False.
However, InlineModelAdmin by default includes jquery.min.js as well.
So given a model with N inlines by default we end up with N+1 jqueries.
It wouldn't be that bad, however, what makes it really bad is the fact that if the main form specifies a jquery plugin in the media definition it will be overwritten by vanilla redundant jquery.
The simplest fix would be to implement internal storage in Media object as a set which would remove redundant entries.
Attachments (1)
Change History (12)
comment:1 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
comment:3 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | assigned → closed |
Unable to reproduce. If this is still an issue for you, please provide your forms, models, and admin file or, better yet, a unit test demonstrating the issue.
comment:5 by , 15 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
Ooops, I was wrong, sorry.
However, if one will do that -
class MovieAdmin(admin.ModelAdmin): class Media: js = ("/media/js/jquery.min.js", "media/js/jquery.min.js", "media/js/jquery.min.js")
jquery will get included three times. Furthermore, if one codes up a class like
class MovieAdmin(admin.ModelAdmin): class Media: js = ("/admin_media/js/jquery.min.js", "/admin_media/js/jquery.min.js", "/admin_media/js/jquery.min.js")
none of this declarations will make it through, if jquery already got in the media object. Or all three will appear, if it wasn't there yet.
I think that this behavior is both inconsistent and wrong.
The main use case is that AFAIK the current way of creating pluggable admin/form features is to provide mixins. So,
assuming we have mixins MixinA, MixinB and MixinC then our admin class will probably look like
class MyAdmin(admin.ModelAdmin, MixinA, MixinB, MixinC): class Media: js = MixinA.Media.js + MixinB.Media.js + MixinC.Media.js
and guess what happens if all three use jquery.
comment:6 by , 15 years ago
The root issue is that JS is added in a list comprehension, which generates the list of JS file paths to add before adding any of them; thus the same file path can be added multiple times by a single declaration. Patch attached above resolves this by using a loop which checks after adding each path, and also includes a regression test case which demonstrates the problem and passes after the fix is applied.
comment:7 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:8 by , 15 years ago
comment:9 by , 15 years ago
Note that the fix applied does not deal with the issue of specifying the same file once with a relative path and once with an absolute path; as far as I'm concerned, that's expected behavior for the moment, but maybe down the road we'll come up with some clever normalization trick to keep it from happening.
Correct me if I'm wrong, but I thought there was already a mechanism to limit dupes in the admin media?
http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py#L76