Ticket #5392: 02-admin-template-names.diff

File 02-admin-template-names.diff, 8.0 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)

new version depends on #6002 and on #6010 - they change the same places

  • django/contrib/admin/options.py

    === modified file 'django/contrib/admin/options.py'
     
    452452            request.user.message_set.create(message=msg)
    453453            return HttpResponseRedirect("../")
    454454
    455     def render_change_form(self, request, model, context, add=False, change=False, obj=None):
     455    def render_change_form(self, request, model, template_name, context, add=False, change=False, obj=None):
    456456        opts = model._meta
    457         app_label = opts.app_label
    458457        ordered_objects = opts.get_ordered_objects()
    459458        extra_context = {
    460459            'add': add,
     
    472471            'is_save_as': request.POST.has_key('_saveasnew'),
    473472        }
    474473        context.update(extra_context)
    475         return render_to_response([
    476             "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
    477             "admin/%s/change_form.html" % app_label,
    478             "admin/change_form.html"], context_instance=context)
     474        return render_to_response(template_name, context_instance=context)
    479475
    480476    def add_view(self, request):
    481477        "The 'add' admin view for this model."
    482478        model = self.model
    483479        opts = model._meta
    484         app_label = opts.app_label
    485480
    486481        if not self.has_add_permission(request):
    487482            raise PermissionDenied
     
    528523            'inline_admin_formsets': inline_admin_formsets,
    529524        })
    530525        c.update(self.add_view_extra_context(request))
    531         return self.render_change_form(request, model, c, add=True)
     526        return self.render_change_form(request, model, self.add_view_template_name(request), c, add=True)
    532527
    533528    def change_view(self, request, object_id):
    534529        "The 'change' admin view for this model."
    535530        model = self.model
    536531        opts = model._meta
    537         app_label = opts.app_label
    538532
    539533        try:
    540534            obj = model._default_manager.get(pk=object_id)
     
    604598            'inline_admin_formsets': inline_admin_formsets,
    605599        })
    606600        c.update(self.change_view_extra_context(request, obj))
    607         return self.render_change_form(request, model, c, change=True, obj=obj)
     601        return self.render_change_form(request, model, self.change_view_template_name(request, obj), c, change=True, obj=obj)
    608602
    609603    def changelist_view(self, request):
    610604        "The 'change list' admin view for this model."
    611605        from django.contrib.admin.views.main import ChangeList, ERROR_FLAG
    612         opts = self.model._meta
    613         app_label = opts.app_label
    614606        if not self.has_change_permission(request, None):
    615607            raise PermissionDenied
    616608        try:
     
    632624        })
    633625        c.update({'has_add_permission': self.has_add_permission(request)}),
    634626        c.update(self.changelist_view_extra_context(request, cl))
    635         return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    636                                 'admin/%s/change_list.html' % app_label,
    637                                 'admin/change_list.html'], context_instance=c)
     627        return render_to_response(self.changelist_view_template_name(request, cl),
     628            context_instance=c)
    638629
    639630    def delete_view(self, request, object_id):
    640631        "The 'delete' admin view for this model."
    641632        from django.contrib.contenttypes.models import ContentType
    642633        from django.contrib.admin.models import LogEntry, DELETION
    643634        opts = self.model._meta
    644         app_label = opts.app_label
    645635
    646636        try:
    647637            obj = self.model._default_manager.get(pk=object_id)
     
    680670            "opts": opts,
    681671        }
    682672        extra_context.update(self.delete_view_extra_context(request, obj))
    683         return render_to_response(["admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower() ),
    684                                 "admin/%s/delete_confirmation.html" % app_label ,
    685                                 "admin/delete_confirmation.html"], extra_context, context_instance=template.RequestContext(request))
     673        return render_to_response(self.delete_view_template_name(request, obj),
     674            extra_context, context_instance=template.RequestContext(request))
    686675
    687676    def history_view(self, request, object_id):
    688677        "The 'history' admin view for this model."
     
    700689            'module_name': capfirst(opts.verbose_name_plural),
    701690            'object': obj,
    702691        }
    703         template_list = [
    704             "admin/%s/%s/object_history.html" % (opts.app_label, opts.object_name.lower()),
    705             "admin/%s/object_history.html" % opts.app_label,
    706             "admin/object_history.html"
    707         ]
    708692        extra_context.update(self.history_view_extra_context(request, obj))
    709         return render_to_response(template_list, extra_context, context_instance=template.RequestContext(request))
     693        return render_to_response(self.history_view_template_name(request, obj),
     694            extra_context, context_instance=template.RequestContext(request))
    710695
    711696    def formsets_add(self, request):
    712697        for inline in self.inline_instances:
     
    736721        """ Extra context for the 'history' admin view. """
    737722        return {}
    738723
     724    def add_view_template_name(self, request):
     725        """ Template name for the 'add' admin view. """
     726        opts = self.opts
     727        return [
     728            'admin/%s/%s/change_form.html' % (opts.app_label, opts.object_name.lower()),
     729            'admin/%s/change_form.html' % opts.app_label,
     730            'admin/change_form.html']
     731
     732    def change_view_template_name(self, request, obj):
     733        """ Template name for the 'change' admin view. """
     734        opts = self.opts
     735        return [
     736            'admin/%s/%s/change_form.html' % (opts.app_label, opts.object_name.lower()),
     737            'admin/%s/change_form.html' % opts.app_label,
     738            'admin/change_form.html']
     739
     740    def changelist_view_template_name(self, request, cl):
     741        """ Template name for the 'change list' admin view. """
     742        opts = self.opts
     743        return [
     744            'admin/%s/%s/change_list.html' % (opts.app_label, opts.object_name.lower()),
     745            'admin/%s/change_list.html' % opts.app_label,
     746            'admin/change_list.html']
     747
     748    def delete_view_template_name(self, request, obj):
     749        """ Template name for the 'delete' admin view. """
     750        opts = self.opts
     751        return [
     752            'admin/%s/%s/delete_confirmation.html' % (opts.app_label, opts.object_name.lower()),
     753            'admin/%s/delete_confirmation.html' % opts.app_label,
     754            'admin/delete_confirmation.html']
     755
     756    def history_view_template_name(self, request, obj):
     757        """ Template name for the 'history' admin view. """
     758        opts = self.opts
     759        return [
     760            'admin/%s/%s/object_history.html' % (opts.app_label, opts.object_name.lower()),
     761            'admin/%s/object_history.html' % opts.app_label,
     762            'admin/object_history.html'
     763        ]
     764
    739765class InlineModelAdmin(BaseModelAdmin):
    740766    """
    741767    Options for inline editing of ``model`` instances.
  • django/contrib/admin/sites.py

    === modified file 'django/contrib/admin/sites.py'
     
    298298              'app_list': app_list,
    299299        }
    300300        context.update(self.index_view_extra_context(request))
    301         return render_to_response('admin/index.html', context,
     301        return render_to_response(self.index_view_template_name(request), context,
    302302            context_instance=template.RequestContext(request))
    303303       
    304304    def index_view_extra_context(self, request):
    305305        """ Extra context for the 'index' admin view. """
    306306        return {}
    307307
     308    def index_view_template_name(self, request):
     309        """ Template name for the 'delete' admin view. """
     310        return 'admin/index.html'
     311
    308312# This global object represents the default admin site, for the common case.
    309313# You can instantiate AdminSite in your own code to create a custom admin site.
    310314site = AdminSite()
Back to Top