Ticket #2450: allow_ascending.diff
File allow_ascending.diff, 4.3 KB (added by , 17 years ago) |
---|
-
date_based.py
21 21 latest 22 22 Latest N (defaults to 15) objects by date 23 23 """ 24 25 if date_field[0]==("-"): 26 date_field = date_field[1:] 27 ascending='' 28 else: 29 ascending='-' 30 24 31 if extra_context is None: extra_context = {} 25 32 model = queryset.model 26 33 if not allow_future: … … 30 37 raise Http404, "No %s available" % model._meta.verbose_name 31 38 32 39 if date_list and num_latest: 33 latest = queryset.order_by( '-'+date_field)[:num_latest]40 latest = queryset.order_by(ascending+date_field)[:num_latest] 34 41 else: 35 42 latest = None 36 43 … … 69 76 model = queryset.model 70 77 now = datetime.datetime.now() 71 78 79 if date_field[0]==("-"): 80 date_field = date_field[1:] 81 ascending='' 82 else: 83 ascending='-' 84 72 85 lookup_kwargs = {'%s__year' % date_field: year} 73 86 74 87 # Only bother to check current date if the year isn't in the past and future objects aren't requested. … … 78 91 if not date_list and not allow_empty: 79 92 raise Http404 80 93 if make_object_list: 81 object_list = queryset.filter(**lookup_kwargs) 94 object_list = queryset.filter(**lookup_kwargs).order_by(ascending+date_field) 82 95 else: 83 96 object_list = [] 84 97 if not template_name: … … 123 136 model = queryset.model 124 137 now = datetime.datetime.now() 125 138 139 if date_field[0]==("-"): 140 date_field = date_field[1:] 141 ascending='' 142 else: 143 ascending='-' 144 126 145 # Calculate first and last day of month, for use in a date-range lookup. 127 146 first_day = date.replace(day=1) 128 147 if first_day.month == 12: … … 134 153 # Only bother to check current date if the month isn't in the past and future objects are requested. 135 154 if last_day >= now.date() and not allow_future: 136 155 lookup_kwargs['%s__lte' % date_field] = now 137 object_list = queryset.filter(**lookup_kwargs) 156 object_list = queryset.filter(**lookup_kwargs).order_by(ascending+date_field) 138 157 if not object_list and not allow_empty: 139 158 raise Http404 140 159 … … 185 204 model = queryset.model 186 205 now = datetime.datetime.now() 187 206 207 if date_field[0]==("-"): 208 date_field = date_field[1:] 209 ascending='' 210 else: 211 ascending='-' 212 188 213 # Calculate first and last day of week, for use in a date-range lookup. 189 214 first_day = date 190 215 last_day = date + datetime.timedelta(days=7) … … 193 218 # Only bother to check current date if the week isn't in the past and future objects aren't requested. 194 219 if last_day >= now.date() and not allow_future: 195 220 lookup_kwargs['%s__lte' % date_field] = now 196 object_list = queryset.filter(**lookup_kwargs) 221 object_list = queryset.filter(**lookup_kwargs).order_by(ascending+date_field) 197 222 if not object_list and not allow_empty: 198 223 raise Http404 199 224 if not template_name: … … 238 263 model = queryset.model 239 264 now = datetime.datetime.now() 240 265 266 if date_field[0]==("-"): 267 date_field = date_field[1:] 268 ascending='' 269 else: 270 ascending='-' 271 241 272 if isinstance(model._meta.get_field(date_field), DateTimeField): 242 273 lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} 243 274 else: … … 246 277 # Only bother to check current date if the date isn't in the past and future objects aren't requested. 247 278 if date >= now.date() and not allow_future: 248 279 lookup_kwargs['%s__lte' % date_field] = now 249 object_list = queryset.filter(**lookup_kwargs) 280 object_list = queryset.filter(**lookup_kwargs).order_by(ascending+date_field) 250 281 if not allow_empty and not object_list: 251 282 raise Http404 252 283 … … 308 339 model = queryset.model 309 340 now = datetime.datetime.now() 310 341 342 if date_field[0]==("-"): 343 date_field = date_field[1:] 344 311 345 if isinstance(model._meta.get_field(date_field), DateTimeField): 312 346 lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} 313 347 else: