Ticket #11868: 11868.diff
File 11868.diff, 8.5 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/media/css/base.css
diff --git a/django/contrib/admin/media/css/base.css b/django/contrib/admin/media/css/base.css index c5e385d..9a7a0f2 100644
a b table thead th.descending a { 326 326 background: url(../img/admin/arrow-down.gif) right .4em no-repeat; 327 327 } 328 328 329 table thead th.sorted a span.text { 330 display: block; 331 float: left; 332 } 333 table thead th.sorted a span.sort_pos { 334 display: block; 335 float: right; 336 font-size: .6em; 337 } 338 table thead th.sorted a span.clear{ 339 display: block; 340 clear: both; 341 } 342 329 343 /* ORDERABLE TABLES */ 330 344 331 345 table.orderable tbody tr td:hover { -
django/contrib/admin/templates/admin/change_list_results.html
diff --git a/django/contrib/admin/templates/admin/change_list_results.html b/django/contrib/admin/templates/admin/change_list_results.html index b3fa224..2fd44c8 100644
a b 8 8 <table id="result_list"> 9 9 <thead> 10 10 <tr> 11 {% for header in result_headers %}<th scope="col"{{ header.class_attrib }}> 12 {% if header.sortable %}<a href="{{ header.url }}">{% endif %} 13 {{ header.text|capfirst }} 14 {% if header.sortable %}</a>{% endif %}</th>{% endfor %} 11 {% for header in result_headers %} 12 <th scope="col" {{ header.class_attrib }}> 13 {% if header.sortable %}<a href="{{ header.url }}">{% endif %} 14 <span class="text">{{ header.text|capfirst }}</span> 15 {% if header.sortable %}<span class="sort_pos">{{ header.sort_pos }}</span> 16 <span class="clear"></span> 17 </a>{% endif %} 18 </th>{% endfor %} 15 19 </tr> 16 20 </thead> 17 21 <tbody> -
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 fdf082b..3b34091 100644
a b def result_headers(cl): 110 110 111 111 th_classes = [] 112 112 new_order_type = 'asc' 113 if field_name == cl.order_field or admin_order_field == cl.order_field: 114 th_classes.append('sorted %sending' % cl.order_type.lower()) 115 new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()] 113 ordering_fields = cl.get_ordering_fields() 114 sort_pos = '' 115 if field_name in ordering_fields.keys() or admin_order_field in ordering_fields.keys(): 116 if not field_name in ordering_fields.keys(): 117 field_name = admin_order_field 118 order_type = ordering_fields.get(field_name).lower() 119 sort_pos = ordering_fields.keys().index(field_name) + 1 120 th_classes.append('sorted %sending' % order_type) 121 new_order_type = {'':'asc', 'asc': 'desc', 'desc': ''}[order_type] 122 123 # build new ordering param 124 o_list = [] 125 for f in ordering_fields.keys(): 126 try: 127 n = cl.list_display.index(f) 128 except ValueError: 129 continue 130 131 if f == field_name: 132 if new_order_type == '': 133 continue 134 t = new_order_type 135 else: 136 t = ordering_fields.get(f) 137 138 o_list.append((t=='desc' and '-' or '') + str(n)) 139 140 if field_name not in ordering_fields.keys() and new_order_type: 141 n = cl.list_display.index(field_name) 142 o_list.append((new_order_type=='desc' and '-' or '') + str(n)) 143 144 o_list = ','.join(o_list) 116 145 117 146 yield { 118 147 "text": header, 119 148 "sortable": True, 120 "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), 149 "sort_pos": sort_pos > 0 and len(ordering_fields) > 0 and unicode(sort_pos) or '', 150 "url": cl.get_query_string({ORDER_VAR: o_list}), 121 151 "class_attrib": mark_safe(th_classes and ' class="%s"' % ' '.join(th_classes) or '') 122 152 } 123 153 -
django/contrib/admin/views/main.py
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 170d168..b53806c 100644
a b from django.contrib.admin.util import quote, get_fields_from_path 4 4 from django.core.exceptions import SuspiciousOperation 5 5 from django.core.paginator import InvalidPage 6 6 from django.db import models 7 from django.db.models.query import QuerySet 8 from django.utils.datastructures import SortedDict 7 9 from django.utils.encoding import force_unicode, smart_str 8 10 from django.utils.translation import ugettext, ugettext_lazy 9 11 from django.utils.http import urlencode … … class ChangeList(object): 59 61 self.list_editable = () 60 62 else: 61 63 self.list_editable = list_editable 62 self.order _field, self.order_type= self.get_ordering()64 self.ordering = self.get_ordering() 63 65 self.query = request.GET.get(SEARCH_VAR, '') 64 66 self.query_set = self.get_query_set() 65 67 self.get_results(request) … … class ChangeList(object): 136 138 # manually-specified ordering from the query string. 137 139 ordering = self.model_admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name] 138 140 139 if ordering[0].startswith('-'):140 order_field, order_type = ordering[0][1:], 'desc'141 else:142 order_field, order_type = ordering[0], 'asc'143 141 if ORDER_VAR in params: 144 try: 145 field_name = self.list_display[int(params[ORDER_VAR])] 142 # Clear ordering and used params 143 ordering = [] 144 order_params = params[ORDER_VAR].split(',') 145 for p in order_params: 146 146 try: 147 f = lookup_opts.get_field(field_name) 148 except models.FieldDoesNotExist: 149 # See whether field_name is a name of a non-field 150 # that allows sorting. 147 none, pfx, idx = p.rpartition('-') 148 field_name = self.list_display[int(idx)] 151 149 try: 152 if callable(field_name): 153 attr = field_name 154 elif hasattr(self.model_admin, field_name): 155 attr = getattr(self.model_admin, field_name) 156 else: 157 attr = getattr(self.model, field_name) 158 order_field = attr.admin_order_field 159 except AttributeError: 160 pass 161 else: 162 order_field = f.name 163 except (IndexError, ValueError): 164 pass # Invalid ordering specified. Just use the default. 165 if ORDER_TYPE_VAR in params and params[ORDER_TYPE_VAR] in ('asc', 'desc'): 166 order_type = params[ORDER_TYPE_VAR] 167 return order_field, order_type 150 f = lookup_opts.get_field(field_name) 151 except models.FieldDoesNotExist: 152 # See whether field_name is a name of a non-field 153 # that allows sorting. 154 try: 155 if callable(field_name): 156 attr = field_name 157 elif hasattr(self.model_admin, field_name): 158 attr = getattr(self.model_admin, field_name) 159 else: 160 attr = getattr(self.model, field_name) 161 field_name = attr.admin_order_field 162 except AttributeError: 163 pass 164 else: 165 field_name = f.name 166 167 ordering.append(pfx + field_name) 168 169 except (IndexError, ValueError): 170 pass # Invalid ordering specified. Skip it. 171 172 return ordering 173 174 def get_ordering_fields(self): 175 # Returns a SortedDict of ordering fields and asc/desc 176 ordering_fields = SortedDict() 177 for o in self.ordering: 178 none, t, f = o.rpartition('-') 179 ordering_fields[f] = t == '-' and 'desc' or 'asc' 180 return ordering_fields 168 181 169 182 def get_query_set(self): 170 183 use_distinct = False … … class ChangeList(object): 239 252 break 240 253 241 254 # Set ordering. 242 if self.order _field:243 qs = qs.order_by( '%s%s' % ((self.order_type == 'desc' and '-' or ''), self.order_field))255 if self.ordering: 256 qs = qs.order_by(*self.ordering) 244 257 245 258 # Apply keyword searches. 246 259 def construct_search(field_name):