Ticket #11195: 11195_admin-changelist-cell-class-fieldname.r15458.diff

File 11195_admin-changelist-cell-class-fieldname.r15458.diff, 3.4 KB (added by Antti Kaihola, 14 years ago)

Patch and tests updated for Django r15458 (between 1.3b1 and 1.3)

  • django/contrib/admin/templatetags/admin_list.py

    diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
    index 806be24..9363aed 100644
    a b def items_for_result(cl, result, form):  
    132132    first = True
    133133    pk = cl.lookup_opts.pk.attname
    134134    for field_name in cl.list_display:
    135         row_class = ''
     135        row_classes = ['fieldname_%s' % field_name]
    136136        try:
    137137            f, attr, value = lookup_field(field_name, result, cl.model_admin)
    138138        except (AttributeError, ObjectDoesNotExist):
    def items_for_result(cl, result, form):  
    164164                else:
    165165                    result_repr = display_for_field(value, f)
    166166                if isinstance(f, models.DateField) or isinstance(f, models.TimeField):
    167                     row_class = ' class="nowrap"'
     167                    row_classes.append('nowrap')
    168168        if force_unicode(result_repr) == '':
    169169            result_repr = mark_safe(' ')
     170        row_class = ' class="%s"' % ' '.join(row_classes)
    170171        # If list_display_links not defined, add the link tag to the first field
    171172        if (first and not cl.list_display_links) or field_name in cl.list_display_links:
    172173            table_tag = {True:'th', False:'td'}[first]
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index d320db5..2cd70da 100644
    a b class AdminViewDeletedObjectsTest(TestCase):  
    10171017        response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(3))
    10181018        self.assertContains(response, should_contain)
    10191019
     1020class AdminChangeListFieldNameClassAttrTest(TestCase):
     1021    fixtures = ['admin-views-users.xml']
     1022
     1023    def setUp(self):
     1024        self.client.login(username='super', password='secret')
     1025
     1026    def tearDown(self):
     1027        self.client.logout()
     1028
     1029    def test_class_attributes(self):
     1030        "Cells of the change list table should contain the field name in their class attribute"
     1031        Podcast.objects.create(name="Django Dose",
     1032            release_date=datetime.date.today())
     1033        response = self.client.get('/test_admin/admin/admin_views/podcast/')
     1034        #assert False, response.content
     1035        self.assertContains(
     1036            response, '<td class="fieldname_action_checkbox">')
     1037        self.assertContains(
     1038            response, '<th class="fieldname_name">')
     1039        self.assertContains(
     1040            response, '<td class="fieldname_release_date nowrap">')
     1041
    10201042class AdminViewStringPrimaryKeyTest(TestCase):
    10211043    fixtures = ['admin-views-users.xml', 'string-primary-key.xml']
    10221044
    class AdminViewStringPrimaryKeyTest(TestCase):  
    10471069    def test_changelist_to_changeform_link(self):
    10481070        "The link from the changelist referring to the changeform of the object should be quoted"
    10491071        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/')
    1050         should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk))
     1072        should_contain = """<th class="fieldname___str__"><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk))
    10511073        self.assertContains(response, should_contain)
    10521074
    10531075    def test_recentactions_link(self):
Back to Top