From 726c99776932147a43394dc94c06bebe86acde19 Mon Sep 17 00:00:00 2001
From: Chris Adams <chris@improbable.org>
Date: Mon, 3 Jan 2011 10:03:18 -0500
Subject: [PATCH] admin, auth: replaced render_to_response with TemplateResponse
* Replaced all calls to render_to_response with TemplateResponses for easier
customization
* Add TemplateResponse pointer to admin documentation
The admin view customization section now mentions that the responses may be
customized and points to the TemplateResponse documentation.
* Admin view tests: verify that TemplateResponses are returned
---
django/contrib/admin/actions.py | 7 +--
django/contrib/admin/options.py | 30 +++++-----
django/contrib/admin/sites.py | 20 ++++---
django/contrib/admin/views/decorators.py | 2 +
django/contrib/auth/admin.py | 8 ++--
django/contrib/auth/views.py | 79 ++++++++++++++++++----------
docs/ref/contrib/admin/index.txt | 7 +++
tests/regressiontests/admin_views/tests.py | 25 ++++++---
8 files changed, 112 insertions(+), 66 deletions(-)
diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py
index c68184a..f8d73c5 100644
a
|
b
|
|
2 | 2 | Built-in, globally-available admin actions. |
3 | 3 | """ |
4 | 4 | |
5 | | from django import template |
6 | 5 | from django.core.exceptions import PermissionDenied |
7 | 6 | from django.contrib.admin import helpers |
8 | 7 | from django.contrib.admin.util import get_deleted_objects, model_ngettext |
9 | 8 | from django.db import router |
10 | | from django.shortcuts import render_to_response |
| 9 | from django.template.response import TemplateResponse |
11 | 10 | from django.utils.encoding import force_unicode |
12 | 11 | from django.utils.translation import ugettext_lazy, ugettext as _ |
13 | 12 | |
… |
… |
def delete_selected(modeladmin, request, queryset):
|
76 | 75 | } |
77 | 76 | |
78 | 77 | # Display the confirmation page |
79 | | return render_to_response(modeladmin.delete_selected_confirmation_template or [ |
| 78 | return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ |
80 | 79 | "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.object_name.lower()), |
81 | 80 | "admin/%s/delete_selected_confirmation.html" % app_label, |
82 | 81 | "admin/delete_selected_confirmation.html" |
83 | | ], context, context_instance=template.RequestContext(request)) |
| 82 | ], context=context, current_app=modeladmin.admin_site.name) |
84 | 83 | |
85 | 84 | delete_selected.short_description = ugettext_lazy("Delete selected %(verbose_name_plural)s") |
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index d08e22b..f32b207 100644
a
|
b
|
|
1 | 1 | from functools import update_wrapper, partial |
2 | | from django import forms, template |
| 2 | from django import forms |
3 | 3 | from django.forms.formsets import all_valid |
4 | 4 | from django.forms.models import (modelform_factory, modelformset_factory, |
5 | 5 | inlineformset_factory, BaseInlineFormSet) |
… |
… |
from django.db.models.related import RelatedObject
|
15 | 15 | from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist |
16 | 16 | from django.db.models.sql.constants import LOOKUP_SEP, QUERY_TERMS |
17 | 17 | from django.http import Http404, HttpResponse, HttpResponseRedirect |
18 | | from django.shortcuts import get_object_or_404, render_to_response |
| 18 | from django.shortcuts import get_object_or_404 |
| 19 | from django.template.response import SimpleTemplateResponse, TemplateResponse |
19 | 20 | from django.utils.decorators import method_decorator |
20 | 21 | from django.utils.datastructures import SortedDict |
21 | 22 | from django.utils.html import escape, escapejs |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
708 | 709 | form_template = self.add_form_template |
709 | 710 | else: |
710 | 711 | form_template = self.change_form_template |
711 | | context_instance = template.RequestContext(request, current_app=self.admin_site.name) |
712 | | return render_to_response(form_template or [ |
| 712 | |
| 713 | return TemplateResponse(request, form_template or [ |
713 | 714 | "admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()), |
714 | 715 | "admin/%s/change_form.html" % app_label, |
715 | 716 | "admin/change_form.html" |
716 | | ], context, context_instance=context_instance) |
| 717 | ], context=context, current_app=self.admin_site.name) |
717 | 718 | |
718 | 719 | def response_add(self, request, obj, post_url_continue='../%s/'): |
719 | 720 | """ |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1074 | 1075 | # something is screwed up with the database, so display an error |
1075 | 1076 | # page. |
1076 | 1077 | if ERROR_FLAG in request.GET.keys(): |
1077 | | return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) |
| 1078 | return SimpleTemplateResponse('admin/invalid_setup.html', context={'title': _('Database error')}) |
1078 | 1079 | return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1') |
1079 | 1080 | |
1080 | 1081 | # If the request was POSTed, this might be a bulk action or a bulk |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1183 | 1184 | 'actions_selection_counter': self.actions_selection_counter, |
1184 | 1185 | } |
1185 | 1186 | context.update(extra_context or {}) |
1186 | | context_instance = template.RequestContext(request, current_app=self.admin_site.name) |
1187 | | return render_to_response(self.change_list_template or [ |
| 1187 | |
| 1188 | return TemplateResponse(request, self.change_list_template or [ |
1188 | 1189 | 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), |
1189 | 1190 | 'admin/%s/change_list.html' % app_label, |
1190 | 1191 | 'admin/change_list.html' |
1191 | | ], context, context_instance=context_instance) |
| 1192 | ], context=context, current_app=self.admin_site.name) |
1192 | 1193 | |
1193 | 1194 | @csrf_protect_m |
1194 | 1195 | @transaction.commit_on_success |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1244 | 1245 | "app_label": app_label, |
1245 | 1246 | } |
1246 | 1247 | context.update(extra_context or {}) |
1247 | | context_instance = template.RequestContext(request, current_app=self.admin_site.name) |
1248 | | return render_to_response(self.delete_confirmation_template or [ |
| 1248 | |
| 1249 | return TemplateResponse(request, self.delete_confirmation_template or [ |
1249 | 1250 | "admin/%s/%s/delete_confirmation.html" % (app_label, opts.object_name.lower()), |
1250 | 1251 | "admin/%s/delete_confirmation.html" % app_label, |
1251 | 1252 | "admin/delete_confirmation.html" |
1252 | | ], context, context_instance=context_instance) |
| 1253 | ], context=context, current_app=self.admin_site.name) |
1253 | 1254 | |
1254 | 1255 | def history_view(self, request, object_id, extra_context=None): |
1255 | 1256 | "The 'history' admin view for this model." |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1272 | 1273 | 'app_label': app_label, |
1273 | 1274 | } |
1274 | 1275 | context.update(extra_context or {}) |
1275 | | context_instance = template.RequestContext(request, current_app=self.admin_site.name) |
1276 | | return render_to_response(self.object_history_template or [ |
| 1276 | return TemplateResponse(request, self.object_history_template or [ |
1277 | 1277 | "admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()), |
1278 | 1278 | "admin/%s/object_history.html" % app_label, |
1279 | 1279 | "admin/object_history.html" |
1280 | | ], context, context_instance=context_instance) |
| 1280 | ], context=context, current_app=self.admin_site.name) |
1281 | 1281 | |
1282 | 1282 | class InlineModelAdmin(BaseModelAdmin): |
1283 | 1283 | """ |
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 1f98db8..0485cdd 100644
a
|
b
|
from django.views.decorators.csrf import csrf_protect
|
9 | 9 | from django.db.models.base import ModelBase |
10 | 10 | from django.core.exceptions import ImproperlyConfigured |
11 | 11 | from django.core.urlresolvers import reverse |
12 | | from django.shortcuts import render_to_response |
| 12 | from django.template.response import TemplateResponse |
| 13 | from django.utils.functional import update_wrapper |
13 | 14 | from django.utils.safestring import mark_safe |
14 | 15 | from django.utils.text import capfirst |
15 | 16 | from django.utils.translation import ugettext as _ |
… |
… |
class AdminSite(object):
|
377 | 378 | 'root_path': self.root_path, |
378 | 379 | } |
379 | 380 | context.update(extra_context or {}) |
380 | | context_instance = template.RequestContext(request, current_app=self.name) |
381 | | return render_to_response(self.index_template or 'admin/index.html', context, |
382 | | context_instance=context_instance |
383 | | ) |
| 381 | |
| 382 | return TemplateResponse(request, |
| 383 | self.index_template or 'admin/index.html', |
| 384 | context=context, |
| 385 | current_app=self.name) |
384 | 386 | |
385 | 387 | def app_index(self, request, app_label, extra_context=None): |
386 | 388 | user = request.user |
… |
… |
class AdminSite(object):
|
421 | 423 | 'root_path': self.root_path, |
422 | 424 | } |
423 | 425 | context.update(extra_context or {}) |
424 | | context_instance = template.RequestContext(request, current_app=self.name) |
425 | | return render_to_response(self.app_index_template or ('admin/%s/app_index.html' % app_label, |
426 | | 'admin/app_index.html'), context, |
427 | | context_instance=context_instance |
| 426 | |
| 427 | return TemplateResponse(request, |
| 428 | self.app_index_template or ('admin/%s/app_index.html' % app_label, 'admin/app_index.html'), |
| 429 | context=context, current_app=self.name |
428 | 430 | ) |
429 | 431 | |
430 | 432 | # This global object represents the default admin site, for the common case. |
diff --git a/django/contrib/admin/views/decorators.py b/django/contrib/admin/views/decorators.py
index 9fabe64..686864c 100644
a
|
b
|
|
1 | 1 | from functools import wraps |
| 2 | |
| 3 | from django import template |
2 | 4 | from django.utils.translation import ugettext as _ |
3 | 5 | from django.contrib.admin.forms import AdminAuthenticationForm |
4 | 6 | from django.contrib.auth.views import login |
diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
index 8cd57f5..2d1738c 100644
a
|
b
|
from django.contrib.auth.models import User, Group
|
6 | 6 | from django.contrib import messages |
7 | 7 | from django.core.exceptions import PermissionDenied |
8 | 8 | from django.http import HttpResponseRedirect, Http404 |
9 | | from django.shortcuts import render_to_response, get_object_or_404 |
10 | | from django.template import RequestContext |
| 9 | from django.shortcuts import get_object_or_404 |
| 10 | from django.template.response import TemplateResponse |
11 | 11 | from django.utils.html import escape |
12 | 12 | from django.utils.decorators import method_decorator |
13 | 13 | from django.utils.translation import ugettext, ugettext_lazy as _ |
… |
… |
class UserAdmin(admin.ModelAdmin):
|
119 | 119 | fieldsets = [(None, {'fields': form.base_fields.keys()})] |
120 | 120 | adminForm = admin.helpers.AdminForm(form, fieldsets, {}) |
121 | 121 | |
122 | | return render_to_response(self.change_user_password_template or 'admin/auth/user/change_password.html', { |
| 122 | return TemplateResponse(request, self.change_user_password_template or 'admin/auth/user/change_password.html', { |
123 | 123 | 'title': _('Change password: %s') % escape(user.username), |
124 | 124 | 'adminForm': adminForm, |
125 | 125 | 'form': form, |
… |
… |
class UserAdmin(admin.ModelAdmin):
|
134 | 134 | 'save_as': False, |
135 | 135 | 'show_save': True, |
136 | 136 | 'root_path': self.admin_site.root_path, |
137 | | }, context_instance=RequestContext(request)) |
| 137 | }) |
138 | 138 | |
139 | 139 | def response_add(self, request, obj, post_url_continue='../%s/'): |
140 | 140 | """ |
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index eba83a2..1389fbd 100644
a
|
b
|
import urlparse
|
3 | 3 | from django.conf import settings |
4 | 4 | from django.core.urlresolvers import reverse |
5 | 5 | from django.http import HttpResponseRedirect, QueryDict |
6 | | from django.shortcuts import render_to_response |
7 | | from django.template import RequestContext |
| 6 | from django.template.response import TemplateResponse |
8 | 7 | from django.utils.http import base36_to_int |
9 | 8 | from django.utils.translation import ugettext as _ |
10 | 9 | from django.views.decorators.cache import never_cache |
… |
… |
def login(request, template_name='registration/login.html',
|
39 | 38 | if not redirect_to: |
40 | 39 | redirect_to = settings.LOGIN_REDIRECT_URL |
41 | 40 | |
42 | | # Security check -- don't allow redirection to a different |
| 41 | # Heavier security check -- don't allow redirection to a different |
43 | 42 | # host. |
44 | 43 | elif netloc and netloc != request.get_host(): |
45 | 44 | redirect_to = settings.LOGIN_REDIRECT_URL |
… |
… |
def login(request, template_name='registration/login.html',
|
64 | 63 | 'site': current_site, |
65 | 64 | 'site_name': current_site.name, |
66 | 65 | } |
67 | | context.update(extra_context or {}) |
68 | | return render_to_response(template_name, context, |
69 | | context_instance=RequestContext(request, current_app=current_app)) |
| 66 | |
| 67 | if extra_context is not None: |
| 68 | context.update(extra_context) |
| 69 | |
| 70 | return TemplateResponse(request, template_name, context=context, |
| 71 | current_app=current_app) |
70 | 72 | |
71 | 73 | def logout(request, next_page=None, |
72 | 74 | template_name='registration/logged_out.html', |
… |
… |
def logout(request, next_page=None,
|
90 | 92 | 'site_name': current_site.name, |
91 | 93 | 'title': _('Logged out') |
92 | 94 | } |
93 | | context.update(extra_context or {}) |
94 | | return render_to_response(template_name, context, |
95 | | context_instance=RequestContext(request, current_app=current_app)) |
| 95 | |
| 96 | if extra_context is not None: |
| 97 | context.update(extra_context) |
| 98 | |
| 99 | return TemplateResponse(request, template_name, context=context, |
| 100 | current_app=current_app) |
96 | 101 | else: |
97 | 102 | # Redirect to this page until the session has been cleared. |
98 | 103 | return HttpResponseRedirect(next_page or request.path) |
… |
… |
def password_reset(request, is_admin_site=False,
|
156 | 161 | return HttpResponseRedirect(post_reset_redirect) |
157 | 162 | else: |
158 | 163 | form = password_reset_form() |
| 164 | |
159 | 165 | context = { |
160 | 166 | 'form': form, |
161 | 167 | } |
162 | | context.update(extra_context or {}) |
163 | | return render_to_response(template_name, context, |
164 | | context_instance=RequestContext(request, current_app=current_app)) |
| 168 | if extra_context is not None: |
| 169 | context.update(extra_context) |
| 170 | |
| 171 | return TemplateResponse(request, template_name, context=context, |
| 172 | current_app=current_app) |
165 | 173 | |
166 | 174 | def password_reset_done(request, |
167 | 175 | template_name='registration/password_reset_done.html', |
168 | 176 | current_app=None, extra_context=None): |
| 177 | |
169 | 178 | context = {} |
170 | | context.update(extra_context or {}) |
171 | | return render_to_response(template_name, context, |
172 | | context_instance=RequestContext(request, current_app=current_app)) |
| 179 | |
| 180 | if extra_context is not None: |
| 181 | context.update(extra_context) |
| 182 | |
| 183 | return TemplateResponse(request, template_name, context=context, |
| 184 | current_app=current_app) |
173 | 185 | |
174 | 186 | # Doesn't need csrf_protect since no-one can guess the URL |
175 | 187 | @never_cache |
… |
… |
def password_reset_confirm(request, uidb36=None, token=None,
|
208 | 220 | 'form': form, |
209 | 221 | 'validlink': validlink, |
210 | 222 | } |
211 | | context.update(extra_context or {}) |
212 | | return render_to_response(template_name, context, |
213 | | context_instance=RequestContext(request, current_app=current_app)) |
| 223 | |
| 224 | if extra_context is not None: |
| 225 | context.update(extra_context) |
| 226 | |
| 227 | return TemplateResponse(request, template_name, context=context, |
| 228 | current_app=current_app) |
214 | 229 | |
215 | 230 | def password_reset_complete(request, |
216 | 231 | template_name='registration/password_reset_complete.html', |
… |
… |
def password_reset_complete(request,
|
218 | 233 | context = { |
219 | 234 | 'login_url': settings.LOGIN_URL |
220 | 235 | } |
221 | | context.update(extra_context or {}) |
222 | | return render_to_response(template_name, context, |
223 | | context_instance=RequestContext(request, current_app=current_app)) |
| 236 | |
| 237 | if extra_context is not None: |
| 238 | context.update(extra_context) |
| 239 | |
| 240 | return TemplateResponse(request, template_name, context=context, |
| 241 | current_app=current_app) |
224 | 242 | |
225 | 243 | @csrf_protect |
226 | 244 | @login_required |
… |
… |
def password_change(request,
|
241 | 259 | context = { |
242 | 260 | 'form': form, |
243 | 261 | } |
244 | | context.update(extra_context or {}) |
245 | | return render_to_response(template_name, context, |
246 | | context_instance=RequestContext(request, current_app=current_app)) |
| 262 | |
| 263 | if extra_context is not None: |
| 264 | context.update(extra_context) |
| 265 | |
| 266 | return TemplateResponse(request, template_name, context=context, |
| 267 | current_app=current_app) |
247 | 268 | |
248 | 269 | def password_change_done(request, |
249 | 270 | template_name='registration/password_change_done.html', |
250 | 271 | current_app=None, extra_context=None): |
| 272 | |
251 | 273 | context = {} |
252 | | context.update(extra_context or {}) |
253 | | return render_to_response(template_name, context, |
254 | | context_instance=RequestContext(request, current_app=current_app)) |
| 274 | |
| 275 | if extra_context is not None: |
| 276 | context.update(extra_context) |
| 277 | |
| 278 | return TemplateResponse(request, template_name, context=context, |
| 279 | current_app=current_app) |
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index f97d4eb..633c53f 100644
a
|
b
|
provided some extra mapping data that would not otherwise be available::
|
1064 | 1064 | return super(MyModelAdmin, self).change_view(request, object_id, |
1065 | 1065 | extra_context=my_context) |
1066 | 1066 | |
| 1067 | .. versionadded:: 1.4 |
| 1068 | |
| 1069 | These views now return :class:`~django.template.response.TemplateResponse` |
| 1070 | instances which allow you to easily customize the response data before |
| 1071 | rendering. For more details, see the |
| 1072 | :doc:`TemplateResponse documentation </ref/template-response>`. |
| 1073 | |
1067 | 1074 | ``ModelAdmin`` media definitions |
1068 | 1075 | -------------------------------- |
1069 | 1076 | |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 9b1a738..0537160 100644
a
|
b
|
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
20 | 20 | from django.contrib.admin.views.main import IS_POPUP_VAR |
21 | 21 | from django.forms.util import ErrorList |
22 | 22 | import django.template.context |
| 23 | from django.template.response import TemplateResponse |
23 | 24 | from django.test import TestCase |
24 | 25 | from django.utils import formats |
25 | 26 | from django.utils.cache import get_max_age |
… |
… |
class AdminViewBasicTest(TestCase):
|
76 | 77 | A smoke test to ensure GET on the add_view works. |
77 | 78 | """ |
78 | 79 | response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit) |
| 80 | self.assertIsInstance(response, TemplateResponse) |
79 | 81 | self.assertEqual(response.status_code, 200) |
80 | 82 | |
81 | 83 | def testAddWithGETArgs(self): |
… |
… |
class AdminViewBasicTest(TestCase):
|
91 | 93 | A smoke test to ensure GET on the change_view works. |
92 | 94 | """ |
93 | 95 | response = self.client.get('/test_admin/%s/admin_views/section/1/' % self.urlbit) |
| 96 | self.assertIsInstance(response, TemplateResponse) |
94 | 97 | self.assertEqual(response.status_code, 200) |
95 | 98 | |
96 | 99 | def testBasicEditGetStringPK(self): |
… |
… |
class CustomModelAdminTest(AdminViewBasicTest):
|
488 | 491 | |
489 | 492 | def testCustomAdminSiteLoginForm(self): |
490 | 493 | self.client.logout() |
491 | | request = self.client.get('/test_admin/admin2/') |
492 | | self.assertEqual(request.status_code, 200) |
| 494 | response = self.client.get('/test_admin/admin2/') |
| 495 | self.assertIsInstance(response, TemplateResponse) |
| 496 | self.assertEqual(response.status_code, 200) |
493 | 497 | login = self.client.post('/test_admin/admin2/', { |
494 | 498 | REDIRECT_FIELD_NAME: '/test_admin/admin2/', |
495 | 499 | LOGIN_FORM_KEY: 1, |
496 | 500 | 'username': 'customform', |
497 | 501 | 'password': 'secret', |
498 | 502 | }) |
| 503 | self.assertIsInstance(login, TemplateResponse) |
499 | 504 | self.assertEqual(login.status_code, 200) |
500 | 505 | self.assertContains(login, 'custom form error') |
501 | 506 | |
502 | 507 | def testCustomAdminSiteLoginTemplate(self): |
503 | 508 | self.client.logout() |
504 | 509 | request = self.client.get('/test_admin/admin2/') |
| 510 | self.assertIsInstance(request, TemplateResponse) |
505 | 511 | self.assertTemplateUsed(request, 'custom_admin/login.html') |
506 | 512 | self.assertTrue('Hello from a custom login template' in request.content) |
507 | 513 | |
508 | 514 | def testCustomAdminSiteLogoutTemplate(self): |
509 | 515 | request = self.client.get('/test_admin/admin2/logout/') |
| 516 | self.assertIsInstance(request, TemplateResponse) |
510 | 517 | self.assertTemplateUsed(request, 'custom_admin/logout.html') |
511 | 518 | self.assertTrue('Hello from a custom logout template' in request.content) |
512 | 519 | |
513 | 520 | def testCustomAdminSiteIndexViewAndTemplate(self): |
514 | 521 | request = self.client.get('/test_admin/admin2/') |
| 522 | self.assertIsInstance(request, TemplateResponse) |
515 | 523 | self.assertTemplateUsed(request, 'custom_admin/index.html') |
516 | 524 | self.assertTrue('Hello from a custom index template *bar*' in request.content) |
517 | 525 | |
518 | 526 | def testCustomAdminSitePasswordChangeTemplate(self): |
519 | 527 | request = self.client.get('/test_admin/admin2/password_change/') |
| 528 | self.assertIsInstance(request, TemplateResponse) |
520 | 529 | self.assertTemplateUsed(request, 'custom_admin/password_change_form.html') |
521 | 530 | self.assertTrue('Hello from a custom password change form template' in request.content) |
522 | 531 | |
523 | 532 | def testCustomAdminSitePasswordChangeDoneTemplate(self): |
524 | 533 | request = self.client.get('/test_admin/admin2/password_change/done/') |
| 534 | self.assertIsInstance(request, TemplateResponse) |
525 | 535 | self.assertTemplateUsed(request, 'custom_admin/password_change_done.html') |
526 | 536 | self.assertTrue('Hello from a custom password change done template' in request.content) |
527 | 537 | |
… |
… |
class AdminViewPermissionsTest(TestCase):
|
631 | 641 | self.assertFalse(login.context) |
632 | 642 | self.client.get('/test_admin/admin/logout/') |
633 | 643 | |
634 | | # Test if user enters email address |
| 644 | # Test if user enters e-mail address |
635 | 645 | request = self.client.get('/test_admin/admin/') |
636 | 646 | self.assertEqual(request.status_code, 200) |
637 | 647 | login = self.client.post('/test_admin/admin/', self.super_email_login) |
… |
… |
class AdminViewPermissionsTest(TestCase):
|
641 | 651 | self.assertContains(login, "Please enter a correct username and password.") |
642 | 652 | new_user = User(username='jondoe', password='secret', email='super@example.com') |
643 | 653 | new_user.save() |
644 | | # check to ensure if there are multiple email addresses a user doesn't get a 500 |
| 654 | # check to ensure if there are multiple e-mail addresses a user doesn't get a 500 |
645 | 655 | login = self.client.post('/test_admin/admin/', self.super_email_login) |
646 | 656 | self.assertContains(login, "Please enter a correct username and password.") |
647 | 657 | |
… |
… |
class SecureViewTests(TestCase):
|
1227 | 1237 | # make sure the view removes test cookie |
1228 | 1238 | self.assertEqual(self.client.session.test_cookie_worked(), False) |
1229 | 1239 | |
1230 | | # Test if user enters email address |
| 1240 | # Test if user enters e-mail address |
1231 | 1241 | request = self.client.get('/test_admin/admin/secure-view/') |
1232 | 1242 | self.assertEqual(request.status_code, 200) |
1233 | 1243 | login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login) |
… |
… |
class SecureViewTests(TestCase):
|
1237 | 1247 | self.assertContains(login, "Please enter a correct username and password.") |
1238 | 1248 | new_user = User(username='jondoe', password='secret', email='super@example.com') |
1239 | 1249 | new_user.save() |
1240 | | # check to ensure if there are multiple email addresses a user doesn't get a 500 |
| 1250 | # check to ensure if there are multiple e-mail addresses a user doesn't get a 500 |
1241 | 1251 | login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login) |
1242 | 1252 | self.assertContains(login, "Please enter a correct username and password.") |
1243 | 1253 | |
… |
… |
class AdminActionsTest(TestCase):
|
1874 | 1884 | 'post': 'yes', |
1875 | 1885 | } |
1876 | 1886 | confirmation = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) |
1877 | | self.assertContains(confirmation, "Are you sure you want to delete the selected subscribers") |
| 1887 | self.assertIsInstance(confirmation, TemplateResponse) |
| 1888 | self.assertContains(confirmation, "Are you sure you want to delete the selected subscribers?") |
1878 | 1889 | self.assertTrue(confirmation.content.count(ACTION_CHECKBOX_NAME) == 2) |
1879 | 1890 | response = self.client.post('/test_admin/admin/admin_views/subscriber/', delete_confirmation_data) |
1880 | 1891 | self.assertEqual(Subscriber.objects.count(), 0) |