Ticket #14291: admin_list.py.patch

File admin_list.py.patch, 3.9 KB (added by vjimw, 14 years ago)

admin_list.py patch to add CSS classes for each table cell based on the file field

Line 
1*** /Users/jt/Sites/django-trunk/django/contrib/admin/templatetags/admin_list.py 2010-09-07 14:08:14.000000000 -0700
2--- /Users/jt/Desktop/admin_list.py 2010-09-07 14:11:10.000000000 -0700
3***************
4*** 133,139 ****
5 first = True
6 pk = cl.lookup_opts.pk.attname
7 for field_name in cl.list_display:
8! row_class = ''
9 try:
10 f, attr, value = lookup_field(field_name, result, cl.model_admin)
11 except (AttributeError, ObjectDoesNotExist):
12--- 133,140 ----
13 first = True
14 pk = cl.lookup_opts.pk.attname
15 for field_name in cl.list_display:
16! r_class = []
17! r_class.append(field_name)
18 try:
19 f, attr, value = lookup_field(field_name, result, cl.model_admin)
20 except (AttributeError, ObjectDoesNotExist):
21***************
22*** 161,169 ****
23 else:
24 result_repr = display_for_field(value, f)
25 if isinstance(f, models.DateField) or isinstance(f, models.TimeField):
26! row_class = ' class="nowrap"'
27 if force_unicode(result_repr) == '':
28 result_repr = mark_safe(' ')
29 # If list_display_links not defined, add the link tag to the first field
30 if (first and not cl.list_display_links) or field_name in cl.list_display_links:
31 table_tag = {True:'th', False:'td'}[first]
32--- 162,174 ----
33 else:
34 result_repr = display_for_field(value, f)
35 if isinstance(f, models.DateField) or isinstance(f, models.TimeField):
36! r_class.append('nowrap')
37 if force_unicode(result_repr) == '':
38 result_repr = mark_safe(' ')
39+
40+
41+ added_class_info = ' class="%s"' % (' '.join(r_class))
42+
43 # If list_display_links not defined, add the link tag to the first field
44 if (first and not cl.list_display_links) or field_name in cl.list_display_links:
45 table_tag = {True:'th', False:'td'}[first]
46***************
47*** 178,184 ****
48 value = result.serializable_value(attr)
49 result_id = repr(force_unicode(value))[1:]
50 yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \
51! (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))
52 else:
53 # By default the fields come from ModelAdmin.list_editable, but if we pull
54 # the fields out of the form instead of list_editable custom admins
55--- 183,189 ----
56 value = result.serializable_value(attr)
57 result_id = repr(force_unicode(value))[1:]
58 yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \
59! (table_tag, added_class_info, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))
60 else:
61 # By default the fields come from ModelAdmin.list_editable, but if we pull
62 # the fields out of the form instead of list_editable custom admins
63***************
64*** 188,194 ****
65 result_repr = mark_safe(force_unicode(bf.errors) + force_unicode(bf))
66 else:
67 result_repr = conditional_escape(result_repr)
68! yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr))
69 if form:
70 yield mark_safe(u'<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name]))
71
72--- 193,199 ----
73 result_repr = mark_safe(force_unicode(bf.errors) + force_unicode(bf))
74 else:
75 result_repr = conditional_escape(result_repr)
76! yield mark_safe(u'<td%s>%s</td>' % (added_class_info, result_repr))
77 if form:
78 yield mark_safe(u'<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name]))
79
Back to Top