Ticket #5392: 02-admin-template-names.diff
File 02-admin-template-names.diff, 8.0 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
=== modified file 'django/contrib/admin/options.py'
452 452 request.user.message_set.create(message=msg) 453 453 return HttpResponseRedirect("../") 454 454 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): 456 456 opts = model._meta 457 app_label = opts.app_label458 457 ordered_objects = opts.get_ordered_objects() 459 458 extra_context = { 460 459 'add': add, … … 472 471 'is_save_as': request.POST.has_key('_saveasnew'), 473 472 } 474 473 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) 479 475 480 476 def add_view(self, request): 481 477 "The 'add' admin view for this model." 482 478 model = self.model 483 479 opts = model._meta 484 app_label = opts.app_label485 480 486 481 if not self.has_add_permission(request): 487 482 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, model, c, add=True)526 return self.render_change_form(request, model, 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) … … 604 598 'inline_admin_formsets': inline_admin_formsets, 605 599 }) 606 600 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) 608 602 609 603 def changelist_view(self, request): 610 604 "The 'change list' admin view for this model." 611 605 from django.contrib.admin.views.main import ChangeList, ERROR_FLAG 612 opts = self.model._meta613 app_label = opts.app_label614 606 if not self.has_change_permission(request, None): 615 607 raise PermissionDenied 616 608 try: … … 632 624 }) 633 625 c.update({'has_add_permission': self.has_add_permission(request)}), 634 626 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) 638 629 639 630 def delete_view(self, request, object_id): 640 631 "The 'delete' admin view for this model." 641 632 from django.contrib.contenttypes.models import ContentType 642 633 from django.contrib.admin.models import LogEntry, DELETION 643 634 opts = self.model._meta 644 app_label = opts.app_label645 635 646 636 try: 647 637 obj = self.model._default_manager.get(pk=object_id) … … 680 670 "opts": opts, 681 671 } 682 672 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)) 686 675 687 676 def history_view(self, request, object_id): 688 677 "The 'history' admin view for this model." … … 700 689 'module_name': capfirst(opts.verbose_name_plural), 701 690 'object': obj, 702 691 } 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 ]708 692 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)) 710 695 711 696 def formsets_add(self, request): 712 697 for inline in self.inline_instances: … … 736 721 """ Extra context for the 'history' admin view. """ 737 722 return {} 738 723 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 739 765 class InlineModelAdmin(BaseModelAdmin): 740 766 """ 741 767 Options for inline editing of ``model`` instances. -
django/contrib/admin/sites.py
=== modified file 'django/contrib/admin/sites.py'
298 298 'app_list': app_list, 299 299 } 300 300 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, 302 302 context_instance=template.RequestContext(request)) 303 303 304 304 def index_view_extra_context(self, request): 305 305 """ Extra context for the 'index' admin view. """ 306 306 return {} 307 307 308 def index_view_template_name(self, request): 309 """ Template name for the 'delete' admin view. """ 310 return 'admin/index.html' 311 308 312 # This global object represents the default admin site, for the common case. 309 313 # You can instantiate AdminSite in your own code to create a custom admin site. 310 314 site = AdminSite()