Skip to content

Commit

Permalink
Fixed #31524 -- Removed minified static assets from the admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdufresne authored and carltongibson committed May 14, 2020
1 parent 6c19c2c commit 81ffeda
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 122 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ include MANIFEST.in
include package.json
include *.rst
graft django
prune django/contrib/admin/bin
graft docs
graft extras
graft js_tests
Expand Down
52 changes: 0 additions & 52 deletions django/contrib/admin/bin/compress.py

This file was deleted.

4 changes: 1 addition & 3 deletions django/contrib/admin/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json

from django import forms
from django.conf import settings
from django.contrib.admin.utils import (
display_for_field, flatten_fieldsets, help_text_for_field, label_for_field,
lookup_field,
Expand Down Expand Up @@ -80,8 +79,7 @@ def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
@property
def media(self):
if 'collapse' in self.classes:
extra = '' if settings.DEBUG else '.min'
return forms.Media(js=['admin/js/collapse%s.js' % extra])
return forms.Media(js=['admin/js/collapse.js'])
return forms.Media()

def __iter__(self):
Expand Down
9 changes: 4 additions & 5 deletions django/contrib/admin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ def media(self):
'jquery.init.js',
'core.js',
'admin/RelatedObjectLookups.js',
'actions%s.js' % extra,
'actions.js',
'urlify.js',
'prepopulate%s.js' % extra,
'prepopulate.js',
'vendor/xregexp/xregexp%s.js' % extra,
]
return forms.Media(js=['admin/js/%s' % url for url in js])
Expand Down Expand Up @@ -2024,12 +2024,11 @@ def __init__(self, parent_model, admin_site):
@property
def media(self):
extra = '' if settings.DEBUG else '.min'
js = ['vendor/jquery/jquery%s.js' % extra, 'jquery.init.js',
'inlines%s.js' % extra]
js = ['vendor/jquery/jquery%s.js' % extra, 'jquery.init.js', 'inlines.js']
if self.filter_vertical or self.filter_horizontal:
js.extend(['SelectBox.js', 'SelectFilter2.js'])
if self.classes and 'collapse' in self.classes:
js.append('collapse%s.js' % extra)
js.append('collapse.js')
return forms.Media(js=['admin/js/%s' % url for url in js])

def get_extra(self, request, obj=None, **kwargs):
Expand Down
7 changes: 0 additions & 7 deletions django/contrib/admin/static/admin/js/actions.min.js

This file was deleted.

2 changes: 0 additions & 2 deletions django/contrib/admin/static/admin/js/collapse.min.js

This file was deleted.

11 changes: 0 additions & 11 deletions django/contrib/admin/static/admin/js/inlines.min.js

This file was deleted.

1 change: 0 additions & 1 deletion django/contrib/admin/static/admin/js/prepopulate.min.js

This file was deleted.

27 changes: 0 additions & 27 deletions docs/internals/contributing/writing-code/javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,6 @@ JavaScript patches
Django's admin system leverages the jQuery framework to increase the
capabilities of the admin interface. In conjunction, there is an emphasis on
admin JavaScript performance and minimizing overall admin media file size.
Serving compressed or "minified" versions of JavaScript files is considered
best practice in this regard.

To that end, patches for JavaScript files should include both the original
code for future development (e.g. ``foo.js``), and a compressed version for
production use (e.g. ``foo.min.js``). Any links to the file in the codebase
should point to the compressed version.

Compressing JavaScript
----------------------

To simplify the process of providing optimized JavaScript code, Django
includes a handy Python script which should be used to create a "minified"
version. To run it:

.. console::

$ python django/contrib/admin/bin/compress.py

Behind the scenes, ``compress.py`` is a front-end for Google's
`Closure Compiler`_ which is written in Java. The Closure Compiler library is
not bundled with Django, but will be installed automatically by ``npm``. The
Closure Compiler library requires `Java`_ 7 or higher.

Please don't forget to run ``compress.py`` and include the ``diff`` of the
minified scripts when submitting patches for Django's JavaScript.

.. _javascript-tests:

Expand Down Expand Up @@ -143,7 +117,6 @@ Then run the tests with:

$ npm test

.. _Closure Compiler: https://developers.google.com/closure/compiler/
.. _EditorConfig: https://editorconfig.org/
.. _Java: https://www.java.com
.. _eslint: https://eslint.org/
Expand Down
5 changes: 5 additions & 0 deletions docs/releases/3.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ Miscellaneous
* The undocumented ``django.contrib.postgres.fields.jsonb.JsonAdapter`` class
is removed.

* Minified JavaScript files are no longer included with the admin. If you
require these files to be minified, consider using a third party app or
external build tool. The minified vendored JavaScript files packaged with the
admin (e.g. :ref:`jquery.min.js <contrib-admin-jquery>`) are still included.

.. _deprecated-features-3.1:

Features deprecated in 3.1
Expand Down
2 changes: 1 addition & 1 deletion tests/admin_inlines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def test_inline_media_only_inline(self):
'my_awesome_inline_scripts.js',
'custom_number.js',
'admin/js/jquery.init.js',
'admin/js/inlines.min.js',
'admin/js/inlines.js',
]
)
self.assertContains(response, 'my_awesome_inline_scripts.js')
Expand Down
16 changes: 4 additions & 12 deletions tests/admin_views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,26 +1229,18 @@ def test_js_minified_only_if_debug_is_false(self):
response = self.client.get(reverse('admin:admin_views_section_add'))
self.assertNotContains(response, 'vendor/jquery/jquery.js')
self.assertContains(response, 'vendor/jquery/jquery.min.js')
self.assertNotContains(response, 'prepopulate.js')
self.assertContains(response, 'prepopulate.min.js')
self.assertNotContains(response, 'actions.js')
self.assertContains(response, 'actions.min.js')
self.assertNotContains(response, 'collapse.js')
self.assertContains(response, 'collapse.min.js')
self.assertNotContains(response, 'inlines.js')
self.assertContains(response, 'inlines.min.js')
self.assertContains(response, 'prepopulate.js')
self.assertContains(response, 'actions.js')
self.assertContains(response, 'collapse.js')
self.assertContains(response, 'inlines.js')
with override_settings(DEBUG=True):
response = self.client.get(reverse('admin:admin_views_section_add'))
self.assertContains(response, 'vendor/jquery/jquery.js')
self.assertNotContains(response, 'vendor/jquery/jquery.min.js')
self.assertContains(response, 'prepopulate.js')
self.assertNotContains(response, 'prepopulate.min.js')
self.assertContains(response, 'actions.js')
self.assertNotContains(response, 'actions.min.js')
self.assertContains(response, 'collapse.js')
self.assertNotContains(response, 'collapse.min.js')
self.assertContains(response, 'inlines.js')
self.assertNotContains(response, 'inlines.min.js')


@override_settings(ROOT_URLCONF='admin_views.urls')
Expand Down

0 comments on commit 81ffeda

Please sign in to comment.