ask, if by deleting an item, if the childen shoud be deleted as well

This commit is contained in:
Oskar Hahn 2011-09-03 12:45:19 +02:00
parent e81de0fa48
commit b626d049fe
2 changed files with 24 additions and 5 deletions

View File

@ -10,6 +10,10 @@
:license: GNU GPL, see LICENSE for more details.
"""
from django.utils.translation import ugettext as _
from django.contrib import messages
from django.core.context_processors import csrf
from openslides.system.api import config_get
@ -53,3 +57,11 @@ def children_list(items):
if item.children:
l += children_list(item.children)
return l
def gen_confirm_form_for_items(request, message, url):
messages.warning(request, '%s<form action="%s" method="post"><input type="hidden" value="%s" name="csrfmiddlewaretoken"><input type="submit" value="%s" /> <input type="submit" name="all" value="%s" /><input type="button" value="%s"></form>' % (message, url, csrf(request)['csrf_token'], _("Yes"), _("with children"), _("No")))
def del_confirm_form_for_items(request, object, name=None):
if name is None:
name = object
gen_confirm_form_for_items(request, _('Do you really want to delete <b>%s</b>?') % name, object.get_absolute_url('delete'))

View File

@ -18,8 +18,8 @@ from django.contrib import messages
from django.utils.translation import ugettext as _
from openslides.agenda.models import Item
from openslides.agenda.api import get_active_item, is_summary, children_list
from openslides.agenda.api import get_active_item, is_summary, children_list, \
del_confirm_form_for_items
from openslides.agenda.forms import ElementOrderForm, MODELFORM
from openslides.application.models import Application
from openslides.assignment.models import Assignment
@ -256,8 +256,15 @@ def delete(request, item_id):
"""
item = Item.objects.get(id=item_id).cast()
if request.method == 'POST':
if 'all' in request.POST:
item.delete()
messages.success(request, _("Item <b>%s</b> and his children were successfully deleted.") % item)
else:
for child in item.children:
child.parent = item.parent
child.save()
item.delete()
messages.success(request, _("Item <b>%s</b> was successfully deleted.") % item)
else:
del_confirm_form(request, item)
del_confirm_form_for_items(request, item)
return redirect(reverse('item_overview'))