Ticket #5392: 04-admin-template-names.diff
File 04-admin-template-names.diff, 7.9 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
=== modified file 'django/contrib/admin/options.py'
457 457 request.user.message_set.create(message=msg) 458 458 return HttpResponseRedirect(redirect_url) 459 459 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): 461 461 model = self.model 462 462 opts = model._meta 463 app_label = opts.app_label464 463 ordered_objects = opts.get_ordered_objects() 465 464 extra_context = { 466 465 'add': add, … … 478 477 'is_save_as': request.POST.has_key('_saveasnew'), 479 478 } 480 479 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) 485 481 486 482 def add_view(self, request): 487 483 "The 'add' admin view for this model." 488 484 model = self.model 489 485 opts = model._meta 490 app_label = opts.app_label491 486 492 487 if not self.has_add_permission(request): 493 488 raise PermissionDenied … … 528 523 'inline_admin_formsets': inline_admin_formsets, 529 524 }) 530 525 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) 532 527 533 528 def change_view(self, request, object_id): 534 529 "The 'change' admin view for this model." 535 530 model = self.model 536 531 opts = model._meta 537 app_label = opts.app_label538 532 539 533 try: 540 534 obj = model._default_manager.get(pk=object_id) … … 606 600 'inline_admin_formsets': inline_admin_formsets, 607 601 }) 608 602 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) 610 604 611 605 def changelist_view(self, request): 612 606 "The 'change list' admin view for this model." 613 607 from django.contrib.admin.views.main import ChangeList, ERROR_FLAG 614 opts = self.model._meta615 app_label = opts.app_label616 608 if not self.has_change_permission(request): 617 609 raise PermissionDenied 618 610 try: … … 634 626 }) 635 627 c.update({'has_add_permission': self.has_add_permission(request)}), 636 628 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) 640 631 641 632 def delete_view(self, request, object_id): 642 633 "The 'delete' admin view for this model." 643 634 from django.contrib.contenttypes.models import ContentType 644 635 from django.contrib.admin.models import LogEntry, DELETION 645 636 opts = self.model._meta 646 app_label = opts.app_label647 637 648 638 try: 649 639 obj = self.model._default_manager.get(pk=object_id) … … 682 672 "opts": opts, 683 673 } 684 674 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)) 688 677 689 678 def history_view(self, request, object_id): 690 679 "The 'history' admin view for this model." … … 702 691 'module_name': capfirst(opts.verbose_name_plural), 703 692 'object': obj, 704 693 } 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 ]710 694 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)) 712 697 713 698 def formsets_add(self, request): 714 699 for inline in self.inline_instances: … … 738 723 """ Extra context for the 'history' admin view. """ 739 724 return {} 740 725 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 741 766 class InlineModelAdmin(BaseModelAdmin): 742 767 """ 743 768 Options for inline editing of ``model`` instances. -
django/contrib/admin/sites.py
=== modified file 'django/contrib/admin/sites.py'
297 297 'app_list': app_list, 298 298 } 299 299 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, 301 301 context_instance=template.RequestContext(request)) 302 302 303 303 def index_view_extra_context(self, request): 304 304 """ Extra context for the 'index' admin view. """ 305 305 return {} 306 306 307 def index_view_template_name(self, request): 308 """ Template name for the 'delete' admin view. """ 309 return 'admin/index.html' 310 307 311 # This global object represents the default admin site, for the common case. 308 312 # You can instantiate AdminSite in your own code to create a custom admin site. 309 313 site = AdminSite()