mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
Merge branch 'bugfix/delete-action-message-display' of git://github.com/chrislawlor/django-admin2 into chrislawlor-bugfix/delete-action-message-display
This commit is contained in:
commit
a3eea0aaf9
2 changed files with 33 additions and 1 deletions
|
|
@ -33,13 +33,15 @@ def delete_selected(request, queryset):
|
|||
objects_name = opts.verbose_name
|
||||
else:
|
||||
objects_name = opts.verbose_name_plural
|
||||
objects_name = unicode(objects_name)
|
||||
|
||||
if request.POST.get('confirmed'):
|
||||
# The user has confirmed that they want to delete the objects.
|
||||
if has_permission:
|
||||
num_objects_deleted = len(queryset)
|
||||
queryset.delete()
|
||||
message = "Successfully deleted %d %s" % \
|
||||
(len(queryset), objects_name)
|
||||
(num_objects_deleted, objects_name)
|
||||
messages.add_message(request, messages.INFO, message)
|
||||
return None
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -130,3 +130,33 @@ class PostDeleteViewTest(BaseIntegrationTest):
|
|||
args=(post.pk, )))
|
||||
self.assertRedirects(response, reverse("admin2:blog_post_index"))
|
||||
self.assertFalse(Post.objects.filter(pk=post.pk).exists())
|
||||
|
||||
|
||||
class PostDeleteActionTest(BaseIntegrationTest):
|
||||
"""
|
||||
Tests the behaviour of the 'Delete selected items' action.
|
||||
"""
|
||||
def test_confirmation_page(self):
|
||||
p1 = Post.objects.create(title="A Post Title", body="body")
|
||||
p2 = Post.objects.create(title="A Post Title", body="body")
|
||||
post_data = {
|
||||
'action': 'delete_selected',
|
||||
'selected_model_id': [p1.id, p2.id]
|
||||
}
|
||||
response = self.client.post(reverse("admin2:blog_post_index"),
|
||||
post_data)
|
||||
self.assertContains(response, p1.title)
|
||||
self.assertContains(response, p2.title)
|
||||
|
||||
def test_results_page(self):
|
||||
p1 = Post.objects.create(title="A Post Title", body="body")
|
||||
p2 = Post.objects.create(title="A Post Title", body="body")
|
||||
post_data = {
|
||||
'action': 'delete_selected',
|
||||
'selected_model_id': [p1.id, p2.id],
|
||||
'confirmed': 'yes'
|
||||
}
|
||||
response = self.client.post(reverse("admin2:blog_post_index"),
|
||||
post_data, follow=True)
|
||||
self.assertContains(response, "Successfully deleted 2 posts")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue