Ticket #12292: admin-render-to-response.diff
File admin-render-to-response.diff, 9.5 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
1 from django import forms , template1 from django import forms 2 2 from django.forms.formsets import all_valid 3 3 from django.forms.models import modelform_factory, modelformset_factory, inlineformset_factory 4 4 from django.forms.models import BaseInlineFormSet … … 376 376 for inline in self.inline_instances: 377 377 yield inline.get_formset(request, obj) 378 378 379 def render_to_response(self, request, templates, context): 380 return self.admin_site.render_to_response(request, templates, context) 381 379 382 def log_addition(self, request, object): 380 383 """ 381 384 Log that an object has been successfully added. … … 584 587 'save_on_top': self.save_on_top, 585 588 'root_path': self.admin_site.root_path, 586 589 }) 587 context_instance = template.RequestContext(request, current_app=self.admin_site.name) 588 return render_to_response(self.change_form_template or [ 590 return self.render_to_response(request, self.change_form_template or [ 589 591 "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), 590 592 "admin/%s/change_form.html" % app_label, 591 593 "admin/change_form.html" 592 ], context , context_instance=context_instance)594 ], context) 593 595 594 596 def response_add(self, request, obj, post_url_continue='../%s/'): 595 597 """ … … 907 909 # the 'invalid=1' parameter was already in the query string, something 908 910 # is screwed up with the database, so display an error page. 909 911 if ERROR_FLAG in request.GET.keys(): 910 return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) 912 return self.render_to_response(request, 913 'admin/invalid_setup.html', {'title': _('Database error')}) 911 914 return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') 912 915 913 916 # If the request was POSTed, this might be a bulk action or a bulk edit. … … 983 986 'actions_on_bottom': self.actions_on_bottom, 984 987 } 985 988 context.update(extra_context or {}) 986 context_instance = template.RequestContext(request, current_app=self.admin_site.name) 987 return render_to_response(self.change_list_template or [ 989 return self.render_to_response(request, self.change_list_template or [ 988 990 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), 989 991 'admin/%s/change_list.html' % app_label, 990 992 'admin/change_list.html' 991 ], context , context_instance=context_instance)993 ], context) 992 994 993 995 @csrf_protect 994 996 def delete_view(self, request, object_id, extra_context=None): … … 1040 1042 "app_label": app_label, 1041 1043 } 1042 1044 context.update(extra_context or {}) 1043 context_instance = template.RequestContext(request, current_app=self.admin_site.name)1044 return render_to_response(self.delete_confirmation_template or [1045 return self.render_to_response(request, 1046 self.delete_confirmation_template or [ 1045 1047 "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()), 1046 1048 "admin/%s/delete_confirmation.html" % app_label, 1047 1049 "admin/delete_confirmation.html" 1048 ], context , context_instance=context_instance)1050 ], context) 1049 1051 1050 1052 def history_view(self, request, object_id, extra_context=None): 1051 1053 "The 'history' admin view for this model." … … 1068 1070 'app_label': app_label, 1069 1071 } 1070 1072 context.update(extra_context or {}) 1071 context_instance = template.RequestContext(request, current_app=self.admin_site.name) 1072 return render_to_response(self.object_history_template or [ 1073 return self.render_to_response(request, self.object_history_template or [ 1073 1074 "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()), 1074 1075 "admin/%s/object_history.html" % app_label, 1075 1076 "admin/object_history.html" 1076 ], context , context_instance=context_instance)1077 ], context) 1077 1078 1078 1079 # 1079 1080 # DEPRECATED methods. -
django/contrib/admin/sites.py
1 1 import re 2 from django import http , template2 from django import http 3 3 from django.contrib.admin import ModelAdmin 4 4 from django.contrib.admin import actions 5 5 from django.contrib.auth import authenticate, login … … 8 8 from django.core.exceptions import ImproperlyConfigured 9 9 from django.core.urlresolvers import reverse 10 10 from django.shortcuts import render_to_response 11 from django.template import RequestContext 11 12 from django.utils.functional import update_wrapper 12 13 from django.utils.safestring import mark_safe 13 14 from django.utils.text import capfirst … … 270 271 from django.views.i18n import null_javascript_catalog as javascript_catalog 271 272 return javascript_catalog(request, packages='django.conf') 272 273 274 def render_to_response(self, request, templates, context): 275 context_instance = RequestContext(request, current_app=self.name) 276 return render_to_response(templates, context, 277 context_instance=context_instance) 278 273 279 def logout(self, request): 274 280 """ 275 281 Logs out the user for the given HttpRequest. … … 376 382 'root_path': self.root_path, 377 383 } 378 384 context.update(extra_context or {}) 379 context_instance = template.RequestContext(request, current_app=self.name) 380 return render_to_response(self.index_template or 'admin/index.html', context, 381 context_instance=context_instance 382 ) 385 return self.render_to_response(request, 386 self.index_template or 'admin/index.html', context) 383 387 index = never_cache(index) 384 388 385 389 def display_login_form(self, request, error_message='', extra_context=None): … … 391 395 'root_path': self.root_path, 392 396 } 393 397 context.update(extra_context or {}) 394 context_instance = template.RequestContext(request, current_app=self.name) 395 return render_to_response(self.login_template or 'admin/login.html', context, 396 context_instance=context_instance 397 ) 398 return self.render_to_response(request, 399 self.login_template or 'admin/login.html', context) 398 400 399 401 def app_index(self, request, app_label, extra_context=None): 400 402 user = request.user … … 435 437 'root_path': self.root_path, 436 438 } 437 439 context.update(extra_context or {}) 438 context_instance = template.RequestContext(request, current_app=self.name) 439 return render_to_response(self.app_index_template or ('admin/%s/app_index.html' % app_label, 440 'admin/app_index.html'), context, 441 context_instance=context_instance 442 ) 440 return self.render_to_response(request, 441 self.app_index_template or ('admin/%s/app_index.html' % app_label, 442 'admin/app_index.html'), context) 443 443 444 444 def root(self, request, url): 445 445 """ -
docs/ref/contrib/admin/index.txt
820 820 This uses the ``HttpRequest`` instance to filter the ``Car`` foreign key field 821 821 to only the cars owned by the ``User`` instance. 822 822 823 .. method:: ModelAdmin.render_to_response(self, request, templates, context) 824 825 .. versionadded:: 1.2 826 827 The ``render_to_response`` method on a ``ModelAdmin`` invokes the 828 :meth:`AdminSite.render_to_response` method on its site. Overriding it at the 829 model level allows for the use of external templating languages, or injecting 830 variables into the context. 831 823 832 Other methods 824 833 ~~~~~~~~~~~~~ 825 834 … … 1423 1432 admin template, should provide the ``current_app`` argument to 1424 1433 ``RequestContext`` or ``Context`` when rendering the template. It should 1425 1434 be set to either ``self.name`` if your view is on an ``AdminSite`` or 1426 ``self.admin_site.name`` if your view is on a ``ModelAdmin``. 1435 ``self.admin_site.name`` if your view is on a ``ModelAdmin``. This is taken 1436 care of for you if you use :meth:`AdminSite.render_to_response`. 1427 1437 1438 Overriding template rendering 1439 ----------------------------- 1440 1441 .. method:: AdminSite.render_to_response(self, request, templates, context) 1442 1443 .. versionadded:: 1.2 1444 1445 This method is used to render templates from within the admin views. By default, 1446 it merely creates a :class:`~django.template.RequestContext` instance and 1447 invokes :func:`~django.shortcuts.render_to_response`. It can be overridden, for 1448 example, to add variables to the context of all the site's templates, or to 1449 use an external template language instead of Django's. 1450 1451 The ``request`` argument is the :class:`~django.http.HttpRequest` for the view 1452 requesting that the template be rendered. ``templates`` is either a string 1453 representing a single template to render, or an iterable of strings. For the 1454 latter, the first template in the iterable that exists is used. ``context`` is 1455 a simple Python dictionary to be used as the template's context. 1456 1428 1457 .. _admin-reverse-urls: 1429 1458 1430 1459 Reversing Admin URLs