Ticket #12627: 12627_r12827_with_test.diff
File 12627_r12827_with_test.diff, 3.3 KB (added by , 15 years ago) |
---|
-
django/forms/forms.py
6 6 from django.utils.copycompat import deepcopy 7 7 from django.utils.datastructures import SortedDict 8 8 from django.utils.html import conditional_escape 9 from django.utils.translation import ugettext_lazy as _ 9 10 from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode 10 11 from django.utils.safestring import mark_safe 11 12 … … 292 293 del self.cleaned_data[name] 293 294 294 295 def _clean_form(self): 296 errors = self.error_class() 295 297 try: 296 298 self.cleaned_data = self.clean() 297 299 except ValidationError, e: 298 self._errors[NON_FIELD_ERRORS] = self.error_class(e.messages) 300 errors.extend(e.messages) 301 if not self.fields: 302 errors.append(_(u'No data was submitted.')) 303 if errors: 304 self._errors[NON_FIELD_ERRORS] = errors 299 305 300 306 def _post_clean(self): 301 307 """ -
django/contrib/admin/templates/admin/change_form.html
55 55 56 56 {% submit_row %} 57 57 58 {% if adminform and add %}58 {% if adminform and add and adminform.form.fields %} 59 59 <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script> 60 60 {% endif %} 61 61 -
tests/regressiontests/admin_views/tests.py
1991 1991 response = self.client.get('/test_admin/admin/admin_views/pizza/add/') 1992 1992 self.assertEqual(response.status_code, 200) 1993 1993 1994 def test_all_read_only(self): 1995 """ 1996 #12627 - if all form fields are included in readonly_fields, then the 1997 form should be marked as invalid to prevent saving empty objects 1998 """ 1999 response = \ 2000 self.client.post('/test_admin/admin/admin_views/allreadonly/add/') 2001 self.assertEqual(response.status_code, 200) 2002 2003 1994 2004 class IncompleteFormTest(TestCase): 1995 2005 """ 1996 2006 Tests validation of a ModelForm that doesn't explicitly have all data -
tests/regressiontests/admin_views/models.py
575 575 class PizzaAdmin(admin.ModelAdmin): 576 576 readonly_fields = ('toppings',) 577 577 578 class AllReadOnly(models.Model): 579 name = models.CharField(max_length=255) 580 581 class AllReadOnlyAdmin(admin.ModelAdmin): 582 readonly_fields = ('name',) 583 578 584 admin.site.register(Article, ArticleAdmin) 579 585 admin.site.register(CustomArticle, CustomArticleAdmin) 580 586 admin.site.register(Section, save_as=True, inlines=[ArticleInline]) … … 621 627 admin.site.register(ChapterXtra1) 622 628 admin.site.register(Pizza, PizzaAdmin) 623 629 admin.site.register(Topping) 630 admin.site.register(AllReadOnly, AllReadOnlyAdmin)