Ticket #1125: admin_stages_extra_context.patch
File admin_stages_extra_context.patch, 3.0 KB (added by , 19 years ago) |
---|
-
django/contrib/admin/views/main.py
230 233 lookup_params.update(opts.one_to_one_field.rel.limit_choices_to) 231 234 self.lookup_params = lookup_params 232 235 233 def change_list(request, app_label, module_name ):236 def change_list(request, app_label, module_name, extra_context={}): 234 237 try: 235 238 cl = ChangeList(request, app_label, module_name) 236 239 except IncorrectLookupParameters: … … 242 245 'cl' : cl 243 246 }) 244 247 c.update({'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}), 248 for key, value in extra_context.items(): 249 if callable(value): 250 c[key] = value() 251 else: 252 c[key] = value 253 245 254 return render_to_response(['admin/%s/%s/change_list' % (app_label, cl.opts.object_name.lower()), 246 255 'admin/%s/change_list' % app_label, 247 256 'admin/change_list'], context_instance=c) … … 392 401 pk_value = getattr(new_object, opts.pk.attname) 393 402 log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.ADDITION) 394 403 395 def add_stage(request, app_label, module_name, show_delete=False, form_url='', post_url='../', post_url_continue='../%s/', object_id_override=None): 404 def add_stage(request, app_label, module_name, show_delete=False, form_url='', post_url='../', 405 post_url_continue='../%s/', object_id_override=None, extra_context={}): 396 406 mod, opts = _get_mod_opts(app_label, module_name) 397 407 if not request.user.has_perm(app_label + '.' + opts.get_add_permission()): 398 408 raise PermissionDenied … … 445 455 }) 446 456 if object_id_override is not None: 447 457 c['object_id'] = object_id_override 458 for key, value in extra_context.items(): 459 if callable(value): 460 c[key] = value() 461 else: 462 c[key] = value 448 463 449 464 return render_change_form(opts, manipulator, app_label, c, add=True) 450 465 add_stage = staff_member_required(add_stage) … … 464 479 change_message = _('No fields changed.') 465 480 log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.CHANGE, change_message) 466 481 467 def change_stage(request, app_label, module_name, object_id ):482 def change_stage(request, app_label, module_name, object_id, extra_context={}): 468 483 mod, opts = _get_mod_opts(app_label, module_name) 469 484 if not request.user.has_perm(app_label + '.' + opts.get_change_permission()): 470 485 raise PermissionDenied … … 539 554 'original': manipulator.original_object, 540 555 'is_popup' : request.REQUEST.has_key('_popup') 541 556 }) 557 for key, value in extra_context.items(): 558 if callable(value): 559 c[key] = value() 560 else: 561 c[key] = value 542 562 543 563 return render_change_form(opts,manipulator, app_label, c, change=True) 544 564