divio/django-cms — pull request #1592 by evildmp (2013-01-16 14:16:21+00:00)
Title: let's tame jQuery imports

These two tiny changes have saved me from a world of pain and misery. I actually cried because of the problems that this pull request addresses.

The changes do two things:

# ``PlaceholderAdmin(ModelAdmin).Media``

Summary: stop importing ``jquery.js.min`` in ``PlaceholderAdmin(ModelAdmin).Media``.

Django's own ``ModelAdmin`` *already* calls in jQuery; so we shouldn't try to import the same thing. (I say 'try' because actually we don't even do that correctly - see the second paragraph at https://github.com/divio/django-cms/issues/1584/.)

Importing ``jquery.js.min`` breaks attempts to make one's own ``admin/base_site.html`` provide a newer jQuery where it's needed.

# ``cms/templates/admin/cms/page/plugin_change_form.html``

Summary: create a ``{% block jquery %}`` around ```` in ``cms/templates/admin/cms/page/plugin_change_form.html``.

A similar issue. The ``plugin_change_form.html`` extends ``admin/base_site.html``, and loads jQuery. Now suppose your plugin needs a newer jQuery - there is no way to make that work without removing the jQuery here.

By putting it in a ``{% block jquery %}``, it's now possible for your plugin's form to point at a template that extends ``plugin_change_form.html`` and overrides that block with the jQuery you want. Or, if your own ``admin/base_site.html`` already imports the jQuery you need, a simple ``{% block jquery %}{% endblock %}`` will prevent the undesired one from being loaded.

Breaks no tests, though I'm not sure how to test for this exactly. Works in practice as described above, on both a ``PlaceholderAdmin``-based admin, and on a plugin.

Saved me from tears.