Ticket #667: extra_lookup_kwargs_callback_r1217.patch
File extra_lookup_kwargs_callback_r1217.patch, 5.1 KB (added by , 19 years ago) |
---|
-
views/generic/date_based.py
21 21 """ 22 22 mod = get_module(app_label, module_name) 23 23 lookup_kwargs = {'%s__lte' % date_field: datetime.datetime.now()} 24 lookup_kwargs.update(extra_lookup_kwargs) 24 if callable(extra_lookup_kwargs): 25 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 26 else: 27 lookup_kwargs.update(extra_lookup_kwargs) 25 28 date_list = getattr(mod, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1] 26 29 if not date_list: 27 30 raise Http404("No %s.%s available" % (app_label, module_name)) … … 68 71 # Only bother to check current date if the year isn't in the past. 69 72 if int(year) >= now.year: 70 73 lookup_kwargs['%s__lte' % date_field] = now 71 lookup_kwargs.update(extra_lookup_kwargs) 74 if callable(extra_lookup_kwargs): 75 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 76 else: 77 lookup_kwargs.update(extra_lookup_kwargs) 72 78 date_list = getattr(mod, "get_%s_list" % date_field)('month', **lookup_kwargs) 73 79 if not date_list: 74 80 raise Http404 … … 120 126 # Only bother to check current date if the month isn't in the past. 121 127 if last_day >= now.date(): 122 128 lookup_kwargs['%s__lte' % date_field] = now 123 lookup_kwargs.update(extra_lookup_kwargs) 129 if callable(extra_lookup_kwargs): 130 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 131 else: 132 lookup_kwargs.update(extra_lookup_kwargs) 124 133 object_list = mod.get_list(**lookup_kwargs) 125 134 if not object_list: 126 135 raise Http404 … … 169 178 # Only bother to check current date if the date isn't in the past. 170 179 if date >= now.date(): 171 180 lookup_kwargs['%s__lte' % date_field] = now 172 lookup_kwargs.update(extra_lookup_kwargs) 181 if callable(extra_lookup_kwargs): 182 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 183 else: 184 lookup_kwargs.update(extra_lookup_kwargs) 173 185 object_list = mod.get_list(**lookup_kwargs) 174 186 if not allow_empty and not object_list: 175 187 raise Http404 … … 233 245 lookup_kwargs['%s__exact' % slug_field] = slug 234 246 else: 235 247 raise AttributeError("Generic detail view must be called with either an object_id or a slug/slugfield") 236 lookup_kwargs.update(extra_lookup_kwargs) 248 if callable(extra_lookup_kwargs): 249 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 250 else: 251 lookup_kwargs.update(extra_lookup_kwargs) 237 252 try: 238 253 object = mod.get_object(**lookup_kwargs) 239 254 except ObjectDoesNotExist: -
views/generic/list_detail.py
36 36 number of objects, total 37 37 """ 38 38 mod = models.get_module(app_label, module_name) 39 lookup_kwargs = extra_lookup_kwargs.copy() 39 if callable(extra_lookup_kwargs): 40 lookup_kwargs = extra_lookup_kwargs(request) 41 else: 42 lookup_kwargs = extra_lookup_kwargs.copy() 40 43 if paginate_by: 41 44 paginator = ObjectPaginator(mod, lookup_kwargs, paginate_by) 42 45 page = request.GET.get('page', 0) … … 98 101 lookup_kwargs['%s__exact' % slug_field] = slug 99 102 else: 100 103 raise AttributeError("Generic detail view must be called with either an object_id or a slug/slug_field") 101 lookup_kwargs.update(extra_lookup_kwargs) 104 if callable(extra_lookup_kwargs): 105 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 106 else: 107 lookup_kwargs.update(extra_lookup_kwargs) 102 108 try: 103 109 object = mod.get_object(**lookup_kwargs) 104 110 except ObjectDoesNotExist: -
views/generic/create_update.py
92 92 lookup_kwargs['%s__exact' % slug_field] = slug 93 93 else: 94 94 raise AttributeError("Generic edit view must be called with either an object_id or a slug/slug_field") 95 lookup_kwargs.update(extra_lookup_kwargs) 95 if callable(extra_lookup_kwargs): 96 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 97 else: 98 lookup_kwargs.update(extra_lookup_kwargs) 96 99 try: 97 100 object = mod.get_object(**lookup_kwargs) 98 101 except ObjectDoesNotExist: … … 168 171 lookup_kwargs['%s__exact' % slug_field] = slug 169 172 else: 170 173 raise AttributeError("Generic delete view must be called with either an object_id or a slug/slug_field") 171 lookup_kwargs.update(extra_lookup_kwargs) 174 if callable(extra_lookup_kwargs): 175 lookup_kwargs.update(extra_lookup_kwargs(request, lookup_kwargs)) 176 else: 177 lookup_kwargs.update(extra_lookup_kwargs) 172 178 try: 173 179 object = mod.get_object(**lookup_kwargs) 174 180 except ObjectDoesNotExist: