Ticket #12627: 12627_r12827_with_test.diff

File 12627_r12827_with_test.diff, 3.3 KB (added by Colin Copeland, 15 years ago)
  • django/forms/forms.py

     
    66from django.utils.copycompat import deepcopy
    77from django.utils.datastructures import SortedDict
    88from django.utils.html import conditional_escape
     9from django.utils.translation import ugettext_lazy as _
    910from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
    1011from django.utils.safestring import mark_safe
    1112
     
    292293                    del self.cleaned_data[name]
    293294
    294295    def _clean_form(self):
     296        errors = self.error_class()
    295297        try:
    296298            self.cleaned_data = self.clean()
    297299        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
    299305
    300306    def _post_clean(self):
    301307        """
  • django/contrib/admin/templates/admin/change_form.html

     
    5555
    5656{% submit_row %}
    5757
    58 {% if adminform and add %}
     58{% if adminform and add and adminform.form.fields %}
    5959   <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>
    6060{% endif %}
    6161
  • tests/regressiontests/admin_views/tests.py

     
    19911991        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
    19921992        self.assertEqual(response.status_code, 200)
    19931993
     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
    19942004class IncompleteFormTest(TestCase):
    19952005    """
    19962006    Tests validation of a ModelForm that doesn't explicitly have all data
  • tests/regressiontests/admin_views/models.py

     
    575575class PizzaAdmin(admin.ModelAdmin):
    576576    readonly_fields = ('toppings',)
    577577
     578class AllReadOnly(models.Model):
     579    name = models.CharField(max_length=255)
     580
     581class AllReadOnlyAdmin(admin.ModelAdmin):
     582    readonly_fields = ('name',)
     583
    578584admin.site.register(Article, ArticleAdmin)
    579585admin.site.register(CustomArticle, CustomArticleAdmin)
    580586admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    621627admin.site.register(ChapterXtra1)
    622628admin.site.register(Pizza, PizzaAdmin)
    623629admin.site.register(Topping)
     630admin.site.register(AllReadOnly, AllReadOnlyAdmin)
Back to Top