Ticket #15661: 15661_refactor.diff

File 15661_refactor.diff, 2.1 KB (added by ShawnMilo, 4 years ago)

Better patch after Jacob's comments.

  • django/contrib/admin/models.py

    diff --git django/contrib/admin/models.py django/contrib/admin/models.py
    index 73810b7..5a1e0d8 100644
    class LogEntry(models.Model): 
    3333    def __repr__(self):
    3434        return smart_unicode(self.action_time)
    3535
     36    def __unicode__(self):
     37
     38        if self.action_flag == ADDITION:
     39            return _('Added "%(object)s".') % {'object': self.object_repr}
     40        elif self.action_flag == CHANGE:
     41            return _('Changed "%(object)s" - %(changes)s') % {'object': self.object_repr, 'changes': self.change_message}
     42        elif self.action_flag == DELETION:
     43            return _('Deleted "%(object)s."') % {'object': self.object_repr}
     44
     45        return_value = _('LogEntry Object')       
     46
    3647    def is_addition(self):
    3748        return self.action_flag == ADDITION
    3849
    class LogEntry(models.Model): 
    5364        """
    5465        if self.content_type and self.object_id:
    5566            return mark_safe(u"%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id)))
    56         return None
    57  No newline at end of file
     67        return None
  • tests/regressiontests/admin_util/tests.py

    diff --git tests/regressiontests/admin_util/tests.py tests/regressiontests/admin_util/tests.py
    index f4b3dd9..e27417f 100644
    class UtilTests(unittest.TestCase): 
    235235            label_for_field('guest', Event, return_attr=True),
    236236            ('awesome guest', None),
    237237        )
     238
     239    def test_logentry_unicode(self):
     240        """
     241        Regression test for #15661
     242        """
     243        log_entry = admin.models.LogEntry()
     244
     245        log_entry.action_flag = admin.models.ADDITION
     246        self.assertTrue(
     247            log_entry.__unicode__().startswith('Added ')
     248        )
     249
     250        log_entry.action_flag = admin.models.CHANGE
     251        self.assertTrue(
     252            log_entry.__unicode__().startswith('Changed ')
     253        )
     254
     255        log_entry.action_flag = admin.models.DELETION
     256        self.assertTrue(
     257            log_entry.__unicode__().startswith('Deleted ')
     258        )
     259
     260       
     261
     262
     263
     264
Back to Top