Ticket #17521: ticket17521.diff
File ticket17521.diff, 5.1 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 3a0ad74..ee4ff97 100644
a b 1 1 from functools import update_wrapper, partial 2 2 from django import forms 3 from django.conf import settings 3 4 from django.forms.formsets import all_valid 4 5 from django.forms.models import (modelform_factory, modelformset_factory, 5 6 inlineformset_factory, BaseInlineFormSet) … … class ModelAdmin(BaseModelAdmin): 394 395 395 396 @property 396 397 def media(self): 398 extra = "" if settings.DEBUG else ".min" 397 399 js = [ 398 400 'core.js', 399 401 'admin/RelatedObjectLookups.js', 400 'jquery .min.js',402 'jquery%s.js' % extra, 401 403 'jquery.init.js' 402 404 ] 403 405 if self.actions is not None: 404 js.append('actions .min.js')406 js.append('actions%s.js' % extra) 405 407 if self.prepopulated_fields: 406 js.extend(['urlify.js', 'prepopulate .min.js'])408 js.extend(['urlify.js', 'prepopulate%s.js' % extra]) 407 409 if self.opts.get_ordered_objects(): 408 410 js.extend(['getElementsBySelector.js', 'dom-drag.js' , 'admin/ordering.js']) 409 411 return forms.Media(js=[static('admin/js/%s' % url) for url in js]) … … class InlineModelAdmin(BaseModelAdmin): 1371 1373 1372 1374 @property 1373 1375 def media(self): 1374 js = ['jquery.min.js', 'jquery.init.js', 'inlines.min.js'] 1376 extra = "" if settings.DEBUG else ".min" 1377 js = ['jquery%s.js' % extra, 'jquery.init.js', "inlines%s.js" % extra] 1375 1378 if self.prepopulated_fields: 1376 js.extend(['urlify.js', 'prepopulate .min.js'])1379 js.extend(['urlify.js', 'prepopulate%s.js' % extra]) 1377 1380 if self.filter_vertical or self.filter_horizontal: 1378 1381 js.extend(['SelectBox.js', 'SelectFilter2.js']) 1379 1382 return forms.Media(js=[static('admin/js/%s' % url) for url in js]) -
tests/regressiontests/modeladmin/tests.py
diff --git a/tests/regressiontests/modeladmin/tests.py b/tests/regressiontests/modeladmin/tests.py index 799d4f5..6c7394c 100644
a b from datetime import date 5 5 from django import forms 6 6 from django.conf import settings 7 7 from django.contrib.admin.options import (ModelAdmin, TabularInline, 8 HORIZONTAL, VERTICAL)8 InlineModelAdmin, HORIZONTAL, VERTICAL) 9 9 from django.contrib.admin.sites import AdminSite 10 10 from django.contrib.admin.validation import validate 11 11 from django.contrib.admin.widgets import AdminDateWidget, AdminRadioSelect … … from django.core.exceptions import ImproperlyConfigured 15 15 from django.forms.models import BaseModelFormSet 16 16 from django.forms.widgets import Select 17 17 from django.test import TestCase 18 from django.test.utils import override_settings 18 19 from django.utils import unittest 19 20 20 21 from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel … … class ModelAdminTests(TestCase): 493 494 list(ma.get_formsets(request))[0]().forms[0].fields.keys(), 494 495 ['extra', 'transport', 'id', 'DELETE', 'main_band']) 495 496 497 def test_media(self): 498 ma = ModelAdmin(Band, self.site) 499 ma.prepopulated_fields = ['something'] 500 ma.actions = ['some action'] 501 502 with override_settings(DEBUG=False): 503 media_js = str(ma.media['js']) 504 self.assertTrue('jquery.min.js' in media_js) 505 self.assertTrue('prepopulate.min.js' in media_js) 506 self.assertTrue('actions.min.js' in media_js) 507 with override_settings(DEBUG=True): 508 media_js = str(ma.media['js']) 509 self.assertFalse('jquery.min.js' in media_js) 510 self.assertTrue('jquery.js' in media_js) 511 self.assertTrue('prepopulate.js' in media_js) 512 self.assertFalse('prepopulate.min.js' in media_js) 513 self.assertTrue('actions.js' in media_js) 514 self.assertFalse('actions.min.js' in media_js) 515 516 517 class InlineModelAdminTest(TestCase): 518 def setUp(self): 519 self.site = AdminSite() 520 521 def test_media(self): 522 class InlineBandAdmin(InlineModelAdmin): 523 model = Band 524 525 ma = InlineBandAdmin(Band, self.site) 526 ma.prepopulated_fields = ['something'] 527 ma.actions = ['some action'] 528 529 with override_settings(DEBUG=False): 530 media_js = str(ma.media['js']) 531 self.assertTrue('jquery.min.js' in media_js) 532 self.assertTrue('prepopulate.min.js' in media_js) 533 self.assertTrue('inlines.min.js' in media_js) 534 with override_settings(DEBUG=True): 535 media_js = str(ma.media['js']) 536 self.assertFalse('jquery.min.js' in media_js) 537 self.assertTrue('jquery.js' in media_js) 538 self.assertTrue('prepopulate.js' in media_js) 539 self.assertFalse('prepopulate.min.js' in media_js) 540 self.assertTrue('inlines.js' in media_js) 541 self.assertFalse('inlines.min.js' in media_js) 542 496 543 497 544 class ValidationTests(unittest.TestCase): 498 545 def test_validation_only_runs_in_debug(self):