Ticket #11195: 11195.1.diff

File 11195.1.diff, 5.3 KB (added by Ramiro Morales, 14 years ago)

akaihola's patch updated to current trunk status. Changed CSS class name prefix to 'fldname-'

  • 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
    a b  
    132132    first = True
    133133    pk = cl.lookup_opts.pk.attname
    134134    for field_name in cl.list_display:
    135         row_class = ''
     135        row_classes = ['fldname-%s' % field_name]
    136136        try:
    137137            f, attr, value = lookup_field(field_name, result, cl.model_admin)
    138138        except (AttributeError, ObjectDoesNotExist):
     
    140140        else:
    141141            if f is None:
    142142                if field_name == u'action_checkbox':
    143                     row_class = ' class="action-checkbox"'
     143                    row_classes = ['action-checkbox']
    144144                allow_tags = getattr(attr, 'allow_tags', False)
    145145                boolean = getattr(attr, 'boolean', False)
    146146                if boolean:
     
    166166                if isinstance(f, models.DateField)\
    167167                or isinstance(f, models.TimeField)\
    168168                or isinstance(f, models.ForeignKey):
    169                     row_class = ' class="nowrap"'
     169                    row_classes.append('nowrap')
    170170        if force_unicode(result_repr) == '':
    171171            result_repr = mark_safe(' ')
     172        row_class = ' class="%s"' % ' '.join(row_classes)
    172173        # If list_display_links not defined, add the link tag to the first field
    173174        if (first and not cl.list_display_links) or field_name in cl.list_display_links:
    174175            table_tag = {True:'th', False:'td'}[first]
  • tests/regressiontests/admin_changelist/tests.py

    diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
    a b  
    3636        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
    3737        context = Context({'cl': cl})
    3838        table_output = template.render(context)
    39         row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td class="nowrap">(None)</td></tr></tbody>'
     39        row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th class="fldname-name"><a href="1/">name</a></th><td class="fldname-parent nowrap">(None)</td></tr></tbody>'
    4040        self.assertFalse(table_output.find(row_html) == -1,
    4141            'Failed to find expected row element: %s' % table_output)
    4242
     
    5757        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
    5858        context = Context({'cl': cl})
    5959        table_output = template.render(context)
    60         row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>'
     60        row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th class="fldname-name"><a href="1/">name</a></th><td class="fldname-parent nowrap">Parent object</td></tr></tbody>'
    6161        self.assertFalse(table_output.find(row_html) == -1,
    6262            'Failed to find expected row element: %s' % table_output)
    6363
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    a b  
    10521052        response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(3))
    10531053        self.assertContains(response, should_contain)
    10541054
     1055class AdminChangeListFieldNameClassAttrTest(TestCase):
     1056    fixtures = ['admin-views-users.xml']
     1057
     1058    def setUp(self):
     1059        self.client.login(username='super', password='secret')
     1060
     1061    def tearDown(self):
     1062        self.client.logout()
     1063
     1064    def test_class_attributes(self):
     1065        "Cells of the change list table should contain the field name in their class attribute"
     1066        Podcast.objects.create(name="Django Dose",
     1067            release_date=datetime.date.today())
     1068        response = self.client.get('/test_admin/admin/admin_views/podcast/')
     1069        self.assertContains(
     1070            response, '<th class="fldname-name">')
     1071        self.assertContains(
     1072            response, '<td class="fldname-release_date nowrap">')
     1073        self.assertContains(
     1074            response, '<td class="action-checkbox">')
     1075
    10551076class AdminViewStringPrimaryKeyTest(TestCase):
    10561077    fixtures = ['admin-views-users.xml', 'string-primary-key.xml']
    10571078
     
    10821103    def test_changelist_to_changeform_link(self):
    10831104        "The link from the changelist referring to the changeform of the object should be quoted"
    10841105        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/')
    1085         should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk))
     1106        should_contain = """<th class="fldname-__str__"><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk))
    10861107        self.assertContains(response, should_contain)
    10871108
    10881109    def test_recentactions_link(self):
Back to Top