Ticket #3287: add_admin_boolean_checkmarks_to_callables.diff
File add_admin_boolean_checkmarks_to_callables.diff, 2.1 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/templatetags/admin_list.py
101 101 "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), 102 102 "class_attrib": (th_classes and ' class="%s"' % ' '.join(th_classes) or '')} 103 103 104 def _boolean_icon(field_val): 105 BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'} 106 return '<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) 107 104 108 def items_for_result(cl, result): 105 109 first = True 106 110 pk = cl.lookup_opts.pk.attname … … 114 118 try: 115 119 attr = getattr(result, field_name) 116 120 allow_tags = getattr(attr, 'allow_tags', False) 121 boolean = getattr(attr, 'boolean', False) 117 122 if callable(attr): 118 123 attr = attr() 119 result_repr = str(attr) 124 if boolean: 125 allow_tags = True 126 result_repr = _boolean_icon(attr) 127 else: 128 result_repr = str(attr) 120 129 except (AttributeError, ObjectDoesNotExist): 121 130 result_repr = EMPTY_CHANGELIST_VALUE 122 131 else: … … 147 156 row_class = ' class="nowrap"' 148 157 # Booleans are special: We use images. 149 158 elif isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField): 150 BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'} 151 result_repr = '<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) 159 result_repr = _boolean_icon(field_val) 152 160 # FloatFields are special: Zero-pad the decimals. 153 161 elif isinstance(f, models.FloatField): 154 162 if field_val is not None: