Ticket #1125: admin_stages_extra_context.patch

File admin_stages_extra_context.patch, 3.0 KB (added by plisk, 19 years ago)
  • django/contrib/admin/views/main.py

     
    230233            lookup_params.update(opts.one_to_one_field.rel.limit_choices_to)
    231234        self.lookup_params = lookup_params
    232235
    233 def change_list(request, app_label, module_name):
     236def change_list(request, app_label, module_name, extra_context={}):
    234237    try:
    235238        cl = ChangeList(request, app_label, module_name)
    236239    except IncorrectLookupParameters:
     
    242245        'cl' : cl
    243246    })
    244247    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           
    245254    return render_to_response(['admin/%s/%s/change_list' % (app_label, cl.opts.object_name.lower()),
    246255                               'admin/%s/change_list' % app_label,
    247256                               'admin/change_list'], context_instance=c)
     
    392401    pk_value = getattr(new_object, opts.pk.attname)
    393402    log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.ADDITION)
    394403
    395 def add_stage(request, app_label, module_name, show_delete=False, form_url='', post_url='../', post_url_continue='../%s/', object_id_override=None):
     404def 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={}):
    396406    mod, opts = _get_mod_opts(app_label, module_name)
    397407    if not request.user.has_perm(app_label + '.' + opts.get_add_permission()):
    398408        raise PermissionDenied
     
    445455    })
    446456    if object_id_override is not None:
    447457        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
    448463
    449464    return render_change_form(opts, manipulator, app_label, c, add=True)
    450465add_stage = staff_member_required(add_stage)
     
    464479        change_message = _('No fields changed.')
    465480    log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.CHANGE, change_message)
    466481
    467 def change_stage(request, app_label, module_name, object_id):
     482def change_stage(request, app_label, module_name, object_id, extra_context={}):
    468483    mod, opts = _get_mod_opts(app_label, module_name)
    469484    if not request.user.has_perm(app_label + '.' + opts.get_change_permission()):
    470485        raise PermissionDenied
     
    539554        'original': manipulator.original_object,
    540555        'is_popup' : request.REQUEST.has_key('_popup')
    541556    })
     557    for key, value in extra_context.items():
     558        if callable(value):
     559            c[key] = value()
     560        else:
     561            c[key] = value
    542562
    543563    return render_change_form(opts,manipulator, app_label, c, change=True)
    544564
Back to Top