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

File 04-admin-template-names.diff, 7.9 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)
  • django/contrib/admin/options.py

    === modified file 'django/contrib/admin/options.py'
     
    457457        request.user.message_set.create(message=msg)
    458458        return HttpResponseRedirect(redirect_url)
    459459
    460     def render_change_form(self, request, context, obj=None, add=False, change=False):
     460    def render_change_form(self, request, template_name, context, obj=None, add=False, change=False):
    461461        model = self.model
    462462        opts = model._meta
    463         app_label = opts.app_label
    464463        ordered_objects = opts.get_ordered_objects()
    465464        extra_context = {
    466465            'add': add,
     
    478477            'is_save_as': request.POST.has_key('_saveasnew'),
    479478        }
    480479        context.update(extra_context)
    481         return render_to_response([
    482             "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
    483             "admin/%s/change_form.html" % app_label,
    484             "admin/change_form.html"], context_instance=context)
     480        return render_to_response(template_name, context_instance=context)
    485481
    486482    def add_view(self, request):
    487483        "The 'add' admin view for this model."
    488484        model = self.model
    489485        opts = model._meta
    490         app_label = opts.app_label
    491486
    492487        if not self.has_add_permission(request):
    493488            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, c, add=True)
     526        return self.render_change_form(request, 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)
     
    606600            'inline_admin_formsets': inline_admin_formsets,
    607601        })
    608602        c.update(self.change_view_extra_context(request, obj))
    609         return self.render_change_form(request, c, obj, change=True)
     603        return self.render_change_form(request, self.change_view_template_name(request, obj), c, obj, change=True)
    610604
    611605    def changelist_view(self, request):
    612606        "The 'change list' admin view for this model."
    613607        from django.contrib.admin.views.main import ChangeList, ERROR_FLAG
    614         opts = self.model._meta
    615         app_label = opts.app_label
    616608        if not self.has_change_permission(request):
    617609            raise PermissionDenied
    618610        try:
     
    634626        })
    635627        c.update({'has_add_permission': self.has_add_permission(request)}),
    636628        c.update(self.changelist_view_extra_context(request))
    637         return render_to_response(['admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    638                                 'admin/%s/change_list.html' % app_label,
    639                                 'admin/change_list.html'], context_instance=c)
     629        return render_to_response(self.changelist_view_template_name(request),
     630            context_instance=c)
    640631
    641632    def delete_view(self, request, object_id):
    642633        "The 'delete' admin view for this model."
    643634        from django.contrib.contenttypes.models import ContentType
    644635        from django.contrib.admin.models import LogEntry, DELETION
    645636        opts = self.model._meta
    646         app_label = opts.app_label
    647637
    648638        try:
    649639            obj = self.model._default_manager.get(pk=object_id)
     
    682672            "opts": opts,
    683673        }
    684674        extra_context.update(self.delete_view_extra_context(request, obj))
    685         return render_to_response(["admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower() ),
    686                                 "admin/%s/delete_confirmation.html" % app_label ,
    687                                 "admin/delete_confirmation.html"], extra_context, context_instance=template.RequestContext(request))
     675        return render_to_response(self.delete_view_template_name(request, obj),
     676            extra_context, context_instance=template.RequestContext(request))
    688677
    689678    def history_view(self, request, object_id):
    690679        "The 'history' admin view for this model."
     
    702691            'module_name': capfirst(opts.verbose_name_plural),
    703692            'object': obj,
    704693        }
    705         template_list = [
    706             "admin/%s/%s/object_history.html" % (opts.app_label, opts.object_name.lower()),
    707             "admin/%s/object_history.html" % opts.app_label,
    708             "admin/object_history.html"
    709         ]
    710694        extra_context.update(self.history_view_extra_context(request, obj))
    711         return render_to_response(template_list, extra_context, context_instance=template.RequestContext(request))
     695        return render_to_response(self.history_view_template_name(request, obj),
     696            extra_context, context_instance=template.RequestContext(request))
    712697
    713698    def formsets_add(self, request):
    714699        for inline in self.inline_instances:
     
    738723        """ Extra context for the 'history' admin view. """
    739724        return {}
    740725
     726    def add_view_template_name(self, request):
     727        """ Template name for the 'add' admin view. """
     728        opts = self.opts
     729        return [
     730            "admin/%s/%s/change_form.html" % (opts.app_label, opts.object_name.lower()),
     731            "admin/%s/change_form.html" % opts.app_label,
     732            "admin/change_form.html"]
     733
     734    def change_view_template_name(self, request, obj):
     735        """ Template name for the 'change' admin view. """
     736        opts = self.opts
     737        return [
     738            "admin/%s/%s/change_form.html" % (opts.app_label, opts.object_name.lower()),
     739            "admin/%s/change_form.html" % opts.app_label,
     740            "admin/change_form.html"]
     741
     742    def changelist_view_template_name(self, request):
     743        """ Template name for the 'change list' admin view. """
     744        opts = self.opts
     745        return ['admin/%s/%s/change_list.html' % (opts.app_label, opts.object_name.lower()),
     746            'admin/%s/change_list.html' % opts.app_label,
     747            'admin/change_list.html']
     748
     749    def delete_view_template_name(self, request, obj):
     750        """ Template name for the 'delete' admin view. """
     751        opts = self.opts
     752        return [
     753            "admin/%s/%s/delete_confirmation.html" % (opts.app_label, opts.object_name.lower()),
     754            "admin/%s/delete_confirmation.html" % opts.app_label,
     755            "admin/delete_confirmation.html"]
     756
     757    def history_view_template_name(self, request, obj):
     758        """ Template name for the 'history' admin view. """
     759        opts = self.opts
     760        return [
     761            "admin/%s/%s/object_history.html" % (opts.app_label, opts.object_name.lower()),
     762            "admin/%s/object_history.html" % opts.app_label,
     763            "admin/object_history.html"
     764        ]
     765
    741766class InlineModelAdmin(BaseModelAdmin):
    742767    """
    743768    Options for inline editing of ``model`` instances.
  • django/contrib/admin/sites.py

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