Today if we try to override admin page (e.g index and change_list), we have to cut and paste admin template or view functions from original django admin code.
But if admin view functions has templates argument, we only have to call orignal admin function and set our own admin template to override admin pages. I written index and change_list example and those patch If be approved this proposal, I want to create the patch for all of admin view functions. Please your comment. Atsushi Suga (a2c) fix example ####### django/contrib/admin/views/main.py ############ def index(request, templates={}): templates_arg = {'index' : 'admin/index.html'} update_dictonary( templates_arg, templates ) return render_to_response( templates_arg['index'], {'title': _('Site administration')}, context_instance=template.RequestContext(request)) index = staff_member_required(never_cache(index)) def update_dictonary(dst_dict, src_dict): """ override and add src_dict members to dst_dict but keep dst_dict data if src_dict doesn't have same as dst_dict keys. """ for key in src_dict.keys(): dst_dict[key] = src_dict[key] return dst_dict # user view function and template ####### mysite/admin/views.py ########## def admin(request): return django.contrib.admin.views.main.index(request,templates={'index':'admin/ my_index.html'}) ####### mysite/templates/admin/my_index.html ###### {% extends "admin/index.html" %} {% block breadcrumbs %}<p>Insert message here...</p>{% endblock %} {% block userlinks %} {% endblock %} ######## patch ########### Index: django/contrib/admin/views/main.py =================================================================== --- django/contrib/admin/views/main.py (revision 6709) +++ django/contrib/admin/views/main.py (working copy) @@ -229,8 +229,11 @@ "admin/%s/change_form.html" % app_label, "admin/change_form.html"], context_instance=context) -def index(request): - return render_to_response('admin/index.html', {'title': _('Site administration')}, context_instance=template.RequestContext(request)) +def index(request, templates={}): + templates_arg = {'index' : 'admin/index.html'} + update_dictonary( templates_arg, templates ) + + return render_to_response( templates_arg['index'], {'title': _('Site administration')}, context_instance=template.RequestContext(request)) index = staff_member_required(never_cache(index)) def add_stage(request, app_label, model_name, show_delete=False, form_url='', post_url=None, post_url_continue='../%s/', object_id_override=None): @@ -766,7 +769,29 @@ def url_for_result(self, result): return "%s/" % quote(getattr(result, self.pk_attname)) -def change_list(request, app_label, model_name): +def default_change_list_template( *args ): + return ['admin/%s/%s/change_list.html' % args[0],\ + 'admin/%s/change_list.html' % args[1],\ + 'admin/change_list.html'] + +def update_dictonary(dst_dict, src_dict): + """ + override and add src_dict members to dst_dict + but keep dst_dict data if src_dict doesn't have same as dst_dict keys. + """ + for key in src_dict.keys(): + dst_dict[key] = src_dict[key] + + return dst_dict + +def change_list(request, app_label, model_name, templates={}): + + #default + templates_arg = {'change_list': default_change_list_template, + 'invalid' :'admin/invalid_setup.html'} + + update_dictonary( templates_arg, templates ) + model = models.get_model(app_label, model_name) if model is None: raise Http404("App %r, model %r, not found" % (app_label, model_name)) @@ -781,7 +806,8 @@ # the 'invalid=1' parameter was already in the query string, something # is screwed up with the database, so display an error page. if ERROR_FLAG in request.GET.keys(): - return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) + #return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) + return render_to_response(templates_arg['invalid'], {'title': _('Database error')}) return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') c = template.RequestContext(request, { 'title': cl.title, @@ -789,7 +815,11 @@ 'cl': cl, }) c.update({'has_add_permission': c['perms'][app_label] [cl.opts.get_add_permission()]}), - return render_to_response(['admin/%s/%s/change_list.html' % (app_label, cl.opts.object_name.lower()), - 'admin/%s/change_list.html' % app_label, - 'admin/change_list.html'], context_instance=c) + + #return render_to_response(['admin/%s/%s/change_list.html' % (app_label, cl.opts.object_name.lower()), + # 'admin/%s/change_list.html' % app_label, + # 'admin/change_list.html'], context_instance=c) + return render_to_response(templates_arg['change_list'] ((app_label, cl.opts.object_name.lower()),\ + app_label),\ + context_instance=c) change_list = staff_member_required(never_cache(change_list)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---