diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-02-22 03:07:57 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-02-22 03:07:57 +0000 |
| commit | 337d102b8612503bb9dc712bfbf07432a9a96302 (patch) | |
| tree | da1bd4db4345a0549affb4cc99124fd398de6fb7 /tests | |
| parent | 00fb22d83600a1e3ca162257a46e4a2a5004ef2b (diff) | |
Fixed #13510 -- Corrected colspan of non-field-specific error messages in admin app tabular inlines so it isn't greater than the actual number of field cells. Thanks KyleMac for the report and Julien Phalip for the patch fixing the issue.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15626 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/admin_inlines/models.py | 28 | ||||
| -rw-r--r-- | tests/regressiontests/admin_inlines/tests.py | 17 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py index 4e5c4e3ae3..bb299f32b8 100644 --- a/tests/regressiontests/admin_inlines/models.py +++ b/tests/regressiontests/admin_inlines/models.py @@ -6,6 +6,7 @@ from django.db import models from django.contrib import admin from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic +from django import forms class Parent(models.Model): name = models.CharField(max_length=50) @@ -123,3 +124,30 @@ class InlineWeakness(admin.TabularInline): extra = 1 admin.site.register(Fashionista, inlines=[InlineWeakness]) + +# Models for #13510 + +class TitleCollection(models.Model): + pass + +class Title(models.Model): + collection = models.ForeignKey(TitleCollection, blank=True, null=True) + title1 = models.CharField(max_length=100) + title2 = models.CharField(max_length=100) + +class TitleForm(forms.ModelForm): + + def clean(self): + cleaned_data = self.cleaned_data + title1 = cleaned_data.get("title1") + title2 = cleaned_data.get("title2") + if title1 != title2: + raise forms.ValidationError("The two titles must be the same") + return cleaned_data + +class TitleInline(admin.TabularInline): + model = Title + form = TitleForm + extra = 1 + +admin.site.register(TitleCollection, inlines=[TitleInline]) diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index b10474d001..915c6fac8d 100644 --- a/tests/regressiontests/admin_inlines/tests.py +++ b/tests/regressiontests/admin_inlines/tests.py @@ -67,6 +67,23 @@ class TestInline(TestCase): self.assertEqual(response.status_code, 302) self.assertEqual(len(Fashionista.objects.filter(person__firstname='Imelda')), 1) + def test_tabular_non_field_errors(self): + """ + Ensure that non_field_errors are displayed correctly, including the + right value for colspan. Refs #13510. + """ + data = { + 'title_set-TOTAL_FORMS': 1, + 'title_set-INITIAL_FORMS': 0, + 'title_set-MAX_NUM_FORMS': 0, + '_save': u'Save', + 'title_set-0-title1': 'a title', + 'title_set-0-title2': 'a different title', + } + response = self.client.post('/test_admin/admin/admin_inlines/titlecollection/add/', data) + # Here colspan is "4": two fields (title1 and title2), one hidden field and the delete checkbock. + self.assertContains(response, '<tr><td colspan="4"><ul class="errorlist"><li>The two titles must be the same</li></ul></td></tr>') + class TestInlineMedia(TestCase): fixtures = ['admin-views-users.xml'] |
