parent
d3f673a276
commit
68b9a2e291
@ -246,12 +246,25 @@ class ItemDelete(DeleteView):
|
|||||||
url_name_args = []
|
url_name_args = []
|
||||||
|
|
||||||
def get_answer_options(self):
|
def get_answer_options(self):
|
||||||
if self.object.children.exists():
|
"""
|
||||||
return [('all', _("Yes, with all child items."))] + self.answer_options
|
Returns the possible answers to the delete view.
|
||||||
else:
|
|
||||||
return self.answer_options
|
'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():
|
||||||
|
options = [('all', _("Yes, with all child items."))] + self.answer_options
|
||||||
|
else:
|
||||||
|
options = self.answer_options
|
||||||
|
self.item_delete_answer_options = options
|
||||||
|
return options
|
||||||
|
|
||||||
def pre_post_redirect(self, request, *args, **kwargs):
|
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':
|
if self.get_answer() == 'all':
|
||||||
self.object.delete(with_children=True)
|
self.object.delete(with_children=True)
|
||||||
messages.success(
|
messages.success(
|
||||||
|
@ -214,6 +214,14 @@ class ViewTest(TestCase):
|
|||||||
self.assertRedirects(response, '/agenda/')
|
self.assertRedirects(response, '/agenda/')
|
||||||
self.assertFalse(Item.objects.filter(pk=1).exists())
|
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):
|
class ConfigTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user