Ticket #6010: 01-admin-extra-context.diff

File 01-admin-extra-context.diff, 4.1 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)

new version can be applied agains newforms-admin

  • django/contrib/admin/options.py

    === modified file 'django/contrib/admin/options.py'
     
    527527            'media': mark_safe(media),
    528528            'inline_admin_formsets': inline_admin_formsets,
    529529        })
     530        c.update(self.add_view_extra_context(request))
    530531        return self.render_change_form(request, model, c, add=True)
    531532
    532533    def change_view(self, request, object_id):
     
    602603            'media': mark_safe(media),
    603604            'inline_admin_formsets': inline_admin_formsets,
    604605        })
     606        c.update(self.change_view_extra_context(request, obj))
    605607        return self.render_change_form(request, model, c, change=True, obj=obj)
    606608
    607609    def changelist_view(self, request):
     
    629631            'cl': cl,
    630632        })
    631633        c.update({'has_add_permission': self.has_add_permission(request)}),
     634        c.update(self.changelist_view_extra_context(request, cl))
    632635        return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    633636                                'admin/%s/change_list.html' % app_label,
    634637                                'admin/change_list.html'], context_instance=c)
     
    676679            "perms_lacking": perms_needed,
    677680            "opts": opts,
    678681        }
     682        extra_context.update(self.delete_view_extra_context(request, obj))
    679683        return render_to_response(["admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower() ),
    680684                                "admin/%s/delete_confirmation.html" % app_label ,
    681685                                "admin/delete_confirmation.html"], extra_context, context_instance=template.RequestContext(request))
     
    701705            "admin/%s/object_history.html" % opts.app_label,
    702706            "admin/object_history.html"
    703707        ]
     708        extra_context.update(self.history_view_extra_context(request, obj))
    704709        return render_to_response(template_list, extra_context, context_instance=template.RequestContext(request))
    705710
    706711    def formsets_add(self, request):
     
    710715    def formsets_change(self, request, obj):
    711716        for inline in self.inline_instances:
    712717            yield inline.formset_change(request, obj)
     718       
     719    def add_view_extra_context(self, request):
     720        """ Extra context for the 'add' admin view. """
     721        return {}
     722
     723    def change_view_extra_context(self, request, obj):
     724        """ Extra context for the 'change' admin view. """
     725        return {}
     726
     727    def changelist_view_extra_context(self, request, cl):
     728        """ Extra context for the 'change list' admin view. """
     729        return {}
     730
     731    def delete_view_extra_context(self, request, obj):
     732        """ Extra context for the 'delete' admin view. """
     733        return {}
     734
     735    def history_view_extra_context(self, request, obj):
     736        """ Extra context for the 'history' admin view. """
     737        return {}
    713738
    714739class InlineModelAdmin(BaseModelAdmin):
    715740    """
  • django/contrib/admin/sites.py

    === modified file 'django/contrib/admin/sites.py'
     
    293293        for app in app_list:
    294294            app['models'].sort(lambda x, y: cmp(x['name'], y['name']))
    295295
    296         return render_to_response('admin/index.html', {
    297             'title': _('Site administration'),
    298             'app_list': app_list,
    299         }, context_instance=template.RequestContext(request))
     296        context = {
     297              'title': _('Site administration'),
     298              'app_list': app_list,
     299        }
     300        context.update(self.index_view_extra_context(request))
     301        return render_to_response('admin/index.html', context,
     302            context_instance=template.RequestContext(request))
     303       
     304    def index_view_extra_context(self, request):
     305        """ Extra context for the 'index' admin view. """
     306        return {}
    300307
    301308# This global object represents the default admin site, for the common case.
    302309# You can instantiate AdminSite in your own code to create a custom admin site.
Back to Top