From 27e7fcbab015452cb4201f32eb2682bd8dc23feb Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 8 Feb 2011 12:23:23 +0000 Subject: [1.2.X] Fixed #10573 -- Corrected autofocus problem in admin when the first widget displayed is a multiwidget. Thanks to rduffield for the report, and to Ramiro and Julien Phalip for the patch. Backport of r15452 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15456 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/admin_views/models.py | 5 +++++ tests/regressiontests/admin_views/tests.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index b840c0a4b5..60d8d06942 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -629,6 +629,10 @@ class WorkHourAdmin(admin.ModelAdmin): list_display = ('datum', 'employee') list_filter = ('employee',) +class Reservation(models.Model): + start_date = models.DateTimeField() + price = models.IntegerField() + admin.site.register(Article, ArticleAdmin) admin.site.register(CustomArticle, CustomArticleAdmin) admin.site.register(Section, save_as=True, inlines=[ArticleInline]) @@ -664,6 +668,7 @@ admin.site.register(PlotDetails) admin.site.register(CyclicOne) admin.site.register(CyclicTwo) admin.site.register(WorkHour, WorkHourAdmin) +admin.site.register(Reservation) # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. # That way we cover all four cases: diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 97f9061a23..384959c500 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -376,6 +376,29 @@ class AdminViewBasicTest(TestCase): except SuspiciousOperation: self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model") +class AdminJavaScriptTest(AdminViewBasicTest): + def testSingleWidgetFirsFieldFocus(self): + """ + JavaScript-assisted auto-focus on first field. + """ + response = self.client.get('/test_admin/%s/admin_views/picture/add/' % self.urlbit) + self.assertContains( + response, + '' + ) + + def testMultiWidgetFirsFieldFocus(self): + """ + JavaScript-assisted auto-focus should work if a model/ModelAdmin setup + is such that the first form field has a MultiWidget. + """ + response = self.client.get('/test_admin/%s/admin_views/reservation/add/' % self.urlbit) + self.assertContains( + response, + '' + ) + + class SaveAsTests(TestCase): fixtures = ['admin-views-users.xml','admin-views-person.xml'] -- cgit v1.3