Improved on r17454 to ensure that `collapse.js` only gets minified when `DEBUG` is `False`.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17455 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a90aad3511
commit
0f6cf4aba1
|
@ -11,6 +11,7 @@ from django.utils.encoding import force_unicode, smart_unicode
|
||||||
from django.utils.html import escape, conditional_escape
|
from django.utils.html import escape, conditional_escape
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
ACTION_CHECKBOX_NAME = '_selected_action'
|
ACTION_CHECKBOX_NAME = '_selected_action'
|
||||||
|
@ -75,7 +76,10 @@ class Fieldset(object):
|
||||||
|
|
||||||
def _media(self):
|
def _media(self):
|
||||||
if 'collapse' in self.classes:
|
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(js=[static('admin/js/%s' % url) for url in js])
|
||||||
return forms.Media()
|
return forms.Media()
|
||||||
media = property(_media)
|
media = property(_media)
|
||||||
|
|
|
@ -395,7 +395,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media(self):
|
def media(self):
|
||||||
extra = "" if settings.DEBUG else ".min"
|
extra = '' if settings.DEBUG else '.min'
|
||||||
js = [
|
js = [
|
||||||
'core.js',
|
'core.js',
|
||||||
'admin/RelatedObjectLookups.js',
|
'admin/RelatedObjectLookups.js',
|
||||||
|
@ -1373,8 +1373,8 @@ class InlineModelAdmin(BaseModelAdmin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media(self):
|
def media(self):
|
||||||
extra = "" if settings.DEBUG else ".min"
|
extra = '' if settings.DEBUG else '.min'
|
||||||
js = ['jquery%s.js' % extra, 'jquery.init.js', "inlines%s.js" % extra]
|
js = ['jquery%s.js' % extra, 'jquery.init.js', 'inlines%s.js' % extra]
|
||||||
if self.prepopulated_fields:
|
if self.prepopulated_fields:
|
||||||
js.extend(['urlify.js', 'prepopulate%s.js' % extra])
|
js.extend(['urlify.js', 'prepopulate%s.js' % extra])
|
||||||
if self.filter_vertical or self.filter_horizontal:
|
if self.filter_vertical or self.filter_horizontal:
|
||||||
|
|
|
@ -35,7 +35,19 @@ callable_year.admin_order_field = 'date'
|
||||||
|
|
||||||
class ArticleInline(admin.TabularInline):
|
class ArticleInline(admin.TabularInline):
|
||||||
model = Article
|
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):
|
class ChapterInline(admin.TabularInline):
|
||||||
model = Chapter
|
model = Chapter
|
||||||
|
@ -512,6 +524,7 @@ class ReportAdmin(admin.ModelAdmin):
|
||||||
name='cable_extra'),
|
name='cable_extra'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
site = admin.AdminSite(name="admin")
|
site = admin.AdminSite(name="admin")
|
||||||
site.register(Article, ArticleAdmin)
|
site.register(Article, ArticleAdmin)
|
||||||
site.register(CustomArticle, CustomArticleAdmin)
|
site.register(CustomArticle, CustomArticleAdmin)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import datetime
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.contenttypes import generic
|
from django.contrib.contenttypes import generic
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
|
@ -573,6 +573,7 @@ class AdminViewBasicTest(TestCase):
|
||||||
except SuspiciousOperation:
|
except SuspiciousOperation:
|
||||||
self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
|
self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
|
||||||
|
|
||||||
|
|
||||||
class AdminJavaScriptTest(AdminViewBasicTest):
|
class AdminJavaScriptTest(AdminViewBasicTest):
|
||||||
urls = "regressiontests.admin_views.urls"
|
urls = "regressiontests.admin_views.urls"
|
||||||
|
|
||||||
|
@ -598,6 +599,40 @@ class AdminJavaScriptTest(AdminViewBasicTest):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
class SaveAsTests(TestCase):
|
||||||
urls = "regressiontests.admin_views.urls"
|
urls = "regressiontests.admin_views.urls"
|
||||||
fixtures = ['admin-views-users.xml','admin-views-person.xml']
|
fixtures = ['admin-views-users.xml','admin-views-person.xml']
|
||||||
|
|
|
@ -494,63 +494,6 @@ class ModelAdminTests(TestCase):
|
||||||
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
|
list(ma.get_formsets(request))[0]().forms[0].fields.keys(),
|
||||||
['extra', 'transport', 'id', 'DELETE', 'main_band'])
|
['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):
|
class ValidationTests(unittest.TestCase):
|
||||||
def test_validation_only_runs_in_debug(self):
|
def test_validation_only_runs_in_debug(self):
|
||||||
|
|
Loading…
Reference in New Issue