Merge pull request #913 from ostcar/issue-911
Cache the results of ItemDelete.get_answer_options
This commit is contained in:
commit
2b04980fc7
@ -246,12 +246,25 @@ class ItemDelete(DeleteView):
|
||||
url_name_args = []
|
||||
|
||||
def get_answer_options(self):
|
||||
"""
|
||||
Returns the possible answers to the delete view.
|
||||
|
||||
'all' is a possible answer, when the item has children.
|
||||
"""
|
||||
# Cache the result in the request, so when the children are deleted, the
|
||||
# result does not change
|
||||
try:
|
||||
options = self.item_delete_answer_options
|
||||
except AttributeError:
|
||||
if self.object.children.exists():
|
||||
return [('all', _("Yes, with all child items."))] + self.answer_options
|
||||
options = [('all', _("Yes, with all child items."))] + self.answer_options
|
||||
else:
|
||||
return self.answer_options
|
||||
options = self.answer_options
|
||||
self.item_delete_answer_options = options
|
||||
return options
|
||||
|
||||
def pre_post_redirect(self, request, *args, **kwargs):
|
||||
# TODO: rewrite this method with on_case_all and on_case_yes
|
||||
if self.get_answer() == 'all':
|
||||
self.object.delete(with_children=True)
|
||||
messages.success(
|
||||
|
@ -214,6 +214,14 @@ class ViewTest(TestCase):
|
||||
self.assertRedirects(response, '/agenda/')
|
||||
self.assertFalse(Item.objects.filter(pk=1).exists())
|
||||
|
||||
def test_delete_item_with_children(self):
|
||||
item1 = Item.objects.create(title='item1')
|
||||
item2 = Item.objects.create(title='item2', parent=item1)
|
||||
|
||||
self.adminClient.post('/agenda/%d/del/' % item1.pk, {'all': 'all'})
|
||||
query = Item.objects.filter(pk__in=[item1.pk, item2.pk])
|
||||
self.assertFalse(query)
|
||||
|
||||
|
||||
class ConfigTest(TestCase):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user