Ticket #245: no-legacy-ordering.diff
File no-legacy-ordering.diff, 1.9 KB (added by , 17 years ago) |
---|
-
django/db/models/query.py
35 35 # HELPER FUNCTIONS # 36 36 #################### 37 37 38 # Django currently supports two forms of ordering.39 # Form 1 (deprecated) example:40 # order_by=(('pub_date', 'DESC'), ('headline', 'ASC'), (None, 'RANDOM'))41 # Form 2 (new-style) example:42 # order_by=('-pub_date', 'headline', '?')43 # Form 1 is deprecated and will no longer be supported for Django's first44 # official release. The following code converts from Form 1 to Form 2.45 46 LEGACY_ORDERING_MAPPING = {'ASC': '_', 'DESC': '-_', 'RANDOM': '?'}47 48 def handle_legacy_orderlist(order_list):49 if not order_list or isinstance(order_list[0], basestring):50 return order_list51 else:52 import warnings53 new_order_list = [LEGACY_ORDERING_MAPPING[j.upper()].replace('_', str(i)) for i, j in order_list]54 warnings.warn("%r ordering syntax is deprecated. Use %r instead." % (order_list, new_order_list), DeprecationWarning)55 return new_order_list56 57 38 def orderfield2column(f, opts): 58 39 try: 59 40 return opts.get_field(f, False).column … … 64 45 if prefix.endswith('.'): 65 46 prefix = backend.quote_name(prefix[:-1]) + '.' 66 47 output = [] 67 for f in handle_legacy_orderlist(order_list):48 for f in order_list: 68 49 if f.startswith('-'): 69 50 output.append('%s%s DESC' % (prefix, backend.quote_name(orderfield2column(f[1:], opts)))) 70 51 elif f == '?': … … 526 507 ordering_to_use = self._order_by 527 508 else: 528 509 ordering_to_use = opts.ordering 529 for f in handle_legacy_orderlist(ordering_to_use):510 for f in ordering_to_use: 530 511 if f == '?': # Special case. 531 512 order_by.append(backend.get_random_function_sql()) 532 513 else: