From faae7c0faf859edb9b60a1a45669b9127efa3f37 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 13 Jun 2008 17:26:30 +0000 Subject: newforms-admin: AdminSite index and display_login_form method can now take an optional extra_context argument, allowing you to inject extra template variables in to them from an over-ridden method on a subclass git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7631 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/admin_views/tests.py | 11 +++++++++++ tests/templates/custom_admin/index.html | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 1e3b334221..a70016d540 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -236,8 +236,19 @@ class AdminViewPermissionsTest(TestCase): request = self.client.get('/test_admin/admin/') self.assertTemplateUsed(request, 'custom_admin/index.html') self.assert_('Hello from a custom index template' in request.content) + + # Finally, using monkey patching check we can inject custom_context arguments in to index + original_index = admin.site.index + def index(*args, **kwargs): + kwargs['extra_context'] = {'foo': '*bar*'} + return original_index(*args, **kwargs) + admin.site.index = index + request = self.client.get('/test_admin/admin/') + self.assertTemplateUsed(request, 'custom_admin/index.html') + self.assert_('Hello from a custom index template *bar*' in request.content) self.client.get('/test_admin/admin/logout/') + del admin.site.index # Resets to using the original admin.site.login_template = None admin.site.index_template = None diff --git a/tests/templates/custom_admin/index.html b/tests/templates/custom_admin/index.html index d52033ee2d..75b6ca3d18 100644 --- a/tests/templates/custom_admin/index.html +++ b/tests/templates/custom_admin/index.html @@ -1,6 +1,6 @@ {% extends "admin/index.html" %} {% block content %} -Hello from a custom index template +Hello from a custom index template {{ foo }} {{ block.super }} {% endblock %} -- cgit v1.3