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

File 03-admin-extra-context.diff, 4.0 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)
  • django/contrib/admin/options.py

    === modified file 'django/contrib/admin/options.py'
     
    527527            'media': 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, c, add=True)
    531532   
    532533    def change_view(self, request, object_id):
     
    604605            'media': media,
    605606            'inline_admin_formsets': inline_admin_formsets,
    606607        })
     608        c.update(self.change_view_extra_context(request, obj))
    607609        return self.render_change_form(request, c, obj, change=True)
    608610
    609611    def changelist_view(self, request):
     
    631633            'cl': cl,
    632634        })
    633635        c.update({'has_add_permission': self.has_add_permission(request)}),
     636        c.update(self.changelist_view_extra_context(request))
    634637        return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    635638                                'admin/%s/change_list.html' % app_label,
    636639                                'admin/change_list.html'], context_instance=c)
     
    678681            "perms_lacking": perms_needed,
    679682            "opts": opts,
    680683        }
     684        extra_context.update(self.delete_view_extra_context(request, obj))
    681685        return render_to_response(["admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower() ),
    682686                                "admin/%s/delete_confirmation.html" % app_label ,
    683687                                "admin/delete_confirmation.html"], extra_context, context_instance=template.RequestContext(request))
     
    703707            "admin/%s/object_history.html" % opts.app_label,
    704708            "admin/object_history.html"
    705709        ]
     710        extra_context.update(self.history_view_extra_context(request, obj))
    706711        return render_to_response(template_list, extra_context, context_instance=template.RequestContext(request))
    707712
    708713    def formsets_add(self, request):
     
    712717    def formsets_change(self, request, obj):
    713718        for inline in self.inline_instances:
    714719            yield inline.formset_change(request, obj)
     720       
     721    def add_view_extra_context(self, request):
     722        """ Extra context for the 'add' admin view. """
     723        return {}
     724
     725    def change_view_extra_context(self, request, obj):
     726        """ Extra context for the 'change' admin view. """
     727        return {}
     728
     729    def changelist_view_extra_context(self, request):
     730        """ Extra context for the 'change list' admin view. """
     731        return {}
     732
     733    def delete_view_extra_context(self, request, obj):
     734        """ Extra context for the 'delete' admin view. """
     735        return {}
     736
     737    def history_view_extra_context(self, request, obj):
     738        """ Extra context for the 'history' admin view. """
     739        return {}
    715740
    716741class InlineModelAdmin(BaseModelAdmin):
    717742    """
  • django/contrib/admin/sites.py

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