Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved on r17454 to ensure that `collapse.js` only gets minified wh…

…en `DEBUG` is `False`.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17455 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0f6cf4aba1d3db4be9a0d593becfc10bc4aa1fbe 1 parent a90aad3
@jphalip jphalip authored
View
6 django/contrib/admin/helpers.py
@@ -11,6 +11,7 @@
from django.utils.html import escape, conditional_escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
+from django.conf import settings
ACTION_CHECKBOX_NAME = '_selected_action'
@@ -75,7 +76,10 @@ def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
def _media(self):
if 'collapse' in self.classes:
- js = ['jquery.min.js', 'jquery.init.js', 'collapse.min.js']
+ extra = '' if settings.DEBUG else '.min'
+ js = ['jquery%s.js' % extra,
+ 'jquery.init.js',
+ 'collapse%s.js' % extra]
return forms.Media(js=[static('admin/js/%s' % url) for url in js])
return forms.Media()
media = property(_media)
View
6 django/contrib/admin/options.py
@@ -395,7 +395,7 @@ def urls(self):
@property
def media(self):
- extra = "" if settings.DEBUG else ".min"
+ extra = '' if settings.DEBUG else '.min'
js = [
'core.js',
'admin/RelatedObjectLookups.js',
@@ -1373,8 +1373,8 @@ def __init__(self, parent_model, admin_site):
@property
def media(self):
- extra = "" if settings.DEBUG else ".min"
- js = ['jquery%s.js' % extra, 'jquery.init.js', "inlines%s.js" % extra]
+ extra = '' if settings.DEBUG else '.min'
+ js = ['jquery%s.js' % extra, 'jquery.init.js', 'inlines%s.js' % extra]
if self.prepopulated_fields:
js.extend(['urlify.js', 'prepopulate%s.js' % extra])
if self.filter_vertical or self.filter_horizontal:
View
15 tests/regressiontests/admin_views/admin.py
@@ -35,7 +35,19 @@ def callable_year(dt_value):
class ArticleInline(admin.TabularInline):
model = Article
-
+ prepopulated_fields = {
+ 'title' : ('content',)
+ }
+ fieldsets=(
+ ('Some fields', {
+ 'classes': ('collapse',),
+ 'fields': ('title', 'content')
+ }),
+ ('Some other fields', {
+ 'classes': ('wide',),
+ 'fields': ('date', 'section')
+ })
+ )
class ChapterInline(admin.TabularInline):
model = Chapter
@@ -512,6 +524,7 @@ def get_urls(self):
name='cable_extra'),
)
+
site = admin.AdminSite(name="admin")
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
View
1  tests/regressiontests/admin_views/models.py
@@ -3,7 +3,6 @@
import tempfile
import os
-from django import forms
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
View
35 tests/regressiontests/admin_views/tests.py
@@ -573,6 +573,7 @@ def test_allowed_filtering_15103(self):
except SuspiciousOperation:
self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
+
class AdminJavaScriptTest(AdminViewBasicTest):
urls = "regressiontests.admin_views.urls"
@@ -598,6 +599,40 @@ def testMultiWidgetFirsFieldFocus(self):
)
+ def test_js_minified_only_if_debug_is_false(self):
+ """
+ Ensure that the minified versions of the JS files are only used when
+ DEBUG is False.
+ Refs #17521.
+ """
+ with override_settings(DEBUG=False):
+ response = self.client.get(
+ '/test_admin/%s/admin_views/section/add/' % self.urlbit)
+ self.assertNotContains(response, 'jquery.js')
+ self.assertContains(response, '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')
+ with override_settings(DEBUG=True):
+ response = self.client.get(
+ '/test_admin/%s/admin_views/section/add/' % self.urlbit)
+ self.assertContains(response, 'jquery.js')
+ self.assertNotContains(response, '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')
+
+
class SaveAsTests(TestCase):
urls = "regressiontests.admin_views.urls"
fixtures = ['admin-views-users.xml','admin-views-person.xml']
View
57 tests/regressiontests/modeladmin/tests.py
@@ -494,63 +494,6 @@ class BandAdmin(ModelAdmin):
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
['extra', 'transport', 'id', 'DELETE', 'main_band'])
- def test_media_minified_only_if_debug_is_false(self):
- """
- Ensure that, with ModelAdmin, the minified versions of the JS files are
- only used when DEBUG is False.
- Refs #17521.
- """
- ma = ModelAdmin(Band, self.site)
- ma.prepopulated_fields = ['something']
- ma.actions = ['some action']
-
- with override_settings(DEBUG=False):
- media_js = str(ma.media['js'])
- self.assertFalse('jquery.js' in media_js)
- self.assertTrue('jquery.min.js' in media_js)
- self.assertFalse('prepopulate.js' in media_js)
- self.assertTrue('prepopulate.min.js' in media_js)
- self.assertFalse('actions.js' in media_js)
- self.assertTrue('actions.min.js' in media_js)
- with override_settings(DEBUG=True):
- media_js = str(ma.media['js'])
- self.assertTrue('jquery.js' in media_js)
- self.assertFalse('jquery.min.js' in media_js)
- self.assertTrue('prepopulate.js' in media_js)
- self.assertFalse('prepopulate.min.js' in media_js)
- self.assertTrue('actions.js' in media_js)
- self.assertFalse('actions.min.js' in media_js)
-
- def test_inlines_media_minified_only_if_debug_is_false(self):
- """
- Ensure that, with InlineModelAdmin, the minified versions of the JS
- files are only used when DEBUG is False.
- Refs #17521.
- """
- class InlineBandAdmin(InlineModelAdmin):
- model = Band
-
- ma = InlineBandAdmin(Band, self.site)
- ma.prepopulated_fields = ['something']
- ma.actions = ['some action']
-
- with override_settings(DEBUG=False):
- media_js = str(ma.media['js'])
- self.assertFalse('jquery.js' in media_js)
- self.assertTrue('jquery.min.js' in media_js)
- self.assertFalse('prepopulate.js' in media_js)
- self.assertTrue('prepopulate.min.js' in media_js)
- self.assertFalse('inlines.js' in media_js)
- self.assertTrue('inlines.min.js' in media_js)
- with override_settings(DEBUG=True):
- media_js = str(ma.media['js'])
- self.assertTrue('jquery.js' in media_js)
- self.assertFalse('jquery.min.js' in media_js)
- self.assertTrue('prepopulate.js' in media_js)
- self.assertFalse('prepopulate.min.js' in media_js)
- self.assertTrue('inlines.js' in media_js)
- self.assertFalse('inlines.min.js' in media_js)
-
class ValidationTests(unittest.TestCase):
def test_validation_only_runs_in_debug(self):
Please sign in to comment.
Something went wrong with that request. Please try again.