Ticket #11195: 11195_change_list_thead_classes.patch

File 11195_change_list_thead_classes.patch, 1.8 KB (added by Diederik van der Boor, 14 years ago)

Update change_list, to have a CSS class in the thead. Allows setting column widths.

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

    commit 4c1c00bcea2635c4c962cb5df58d960cceae0841
    Author: Diederik van der Boor <vdboor@edoburu.nl>
    Date:   Fri Apr 22 15:30:29 2011 +0200
    
        Add `col-field_name` class to change_list headers.
        
        This allows setting the column widths; improving the look of  the admin lists.
    
    diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
    index fdf082b..139c0a1 100644
    a b def result_headers(cl):  
    100100            # It is a non-field, but perhaps one that is sortable
    101101            admin_order_field = getattr(attr, "admin_order_field", None)
    102102            if not admin_order_field:
    103                 yield {"text": header}
     103                yield {
     104                    "text": header,
     105                    "class_attrib": mark_safe(' class="col-%s"' % field_name)
     106                }
    104107                continue
    105108
    106109            # So this _is_ a sortable non-field.  Go to the yield
    def result_headers(cl):  
    108111        else:
    109112            admin_order_field = None
    110113
    111         th_classes = []
     114        th_classes = ['col-' + field_name]
    112115        new_order_type = 'asc'
    113116        if field_name == cl.order_field or admin_order_field == cl.order_field:
    114117            th_classes.append('sorted %sending' % cl.order_type.lower())
    def result_headers(cl):  
    118121            "text": header,
    119122            "sortable": True,
    120123            "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}),
    121             "class_attrib": mark_safe(th_classes and ' class="%s"' % ' '.join(th_classes) or '')
     124            "class_attrib": mark_safe(' class="%s"' % ' '.join(th_classes))
    122125        }
    123126
    124127def _boolean_icon(field_val):
Back to Top