Ticket #12952: admin_history.diff

File admin_history.diff, 4.0 KB (added by vasiliyeah, 4 years ago)
  • ../django/contrib/admin/options.py

     
    636636        """
    637637        Construct a change message from a changed object.
    638638        """
     639
     640        def convert_changed_list(obj, changed_data):
     641            cls = type(obj)
     642            verbose_names = []
     643            for field in changed_data:
     644                try:
     645                    verbose_names.append(cls._meta.get_field_by_name(field)[0].verbose_name)
     646                except FieldDoesNotExist:
     647                    verbose_names.append(field)
     648            return verbose_names
     649       
    639650        change_message = []
    640651        if form.changed_data:
    641             change_message.append(_('Changed %s.') % get_text_list(form.changed_data, _('and')))
     652            change_message.append(_('Changed %s.') %
     653                get_text_list(convert_changed_list(form.instance, form.changed_data), _('and')))
    642654
    643655        if formsets:
    644656            for formset in formsets:
     
    648660                                             'object': force_unicode(added_object)})
    649661                for changed_object, changed_fields in formset.changed_objects:
    650662                    change_message.append(_('Changed %(list)s for %(name)s "%(object)s".')
    651                                           % {'list': get_text_list(changed_fields, _('and')),
     663                                          % {'list': get_text_list(convert_changed_list(changed_object, changed_fields),
     664                                                _('and')),
    652665                                             'name': force_unicode(changed_object._meta.verbose_name),
    653666                                             'object': force_unicode(changed_object)})
    654667                for deleted_object in formset.deleted_objects:
  • ../tests/regressiontests/admin_views/tests.py

     
    10471047
    10481048        response = self.client.get('/test_admin/admin/secure-view/')
    10491049        self.assertContains(response, 'id="login-form"')
     1050       
     1051    def testHistoryView(self):
     1052        change_dict = {'title' : 'Ikke fordømt',
     1053                       'content': '<p>edited article</p>',
     1054                       'date_0': '2008-03-18', 'date_1': '10:54:39',
     1055                       'section': 1}
     1056       
     1057        self.client.get('/test_admin/admin/')
     1058        self.client.post('/test_admin/admin/', self.changeuser_login)
     1059        post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict)
     1060        self.assertEqual(Article.objects.get(pk=1).content, '<p>edited article</p>')
     1061        response = self.client.get('/test_admin/admin/admin_views/article/1/history/')
     1062        self.assertEqual(response.status_code, 200)
     1063        self.assertContains(response, u'<td>changeuser (Change User)</td>')
     1064        self.assertContains(response, u'<td>Changed ¿Name?, content and ¿Date published?.</td>')
     1065       
     1066       
     1067       
     1068       
    10501069
    10511070
    10521071class AdminViewDeletedObjectsTest(TestCase):
  • ../tests/regressiontests/admin_views/models.py

     
    2525    """
    2626    A simple article to test admin views. Test backwards compatibility.
    2727    """
    28     title = models.CharField(max_length=100)
     28    title = models.CharField(max_length=100, verbose_name=u'¿Name?')
    2929    content = models.TextField()
    30     date = models.DateTimeField()
    31     section = models.ForeignKey(Section, null=True, blank=True)
     30    date = models.DateTimeField(verbose_name=u'¿Date published?')
     31    section = models.ForeignKey(Section, null=True, blank=True, verbose_name=u'¿Section?')
    3232
    3333    def __unicode__(self):
    3434        return self.title
Back to Top