diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 8ce474efd..e7e5426ec 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -103,6 +103,17 @@ class Item(MPTTModel, SlideMixin): } return ItemOrderForm(initial=initial, prefix="i%d" % self.id) + def delete(self, with_children=False): + """ + Delete the Item. + """ + if not with_children: + for child in self.get_children(): + child.move_to(self.parent) + child.save() + super(Item, self).delete() + Item.objects.rebuild() + def get_absolute_url(self, link='view'): """ Return the URL to this item. By default it is the Link to its diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 387352cd6..57b933f16 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -143,13 +143,10 @@ class ItemDelete(DeleteView): self.object = self.get_object() if 'all' in request.POST: - self.object.delete() + self.object.delete(with_children=True) messages.success(request, _("Item %s and his children were successfully deleted.") % self.object) else: - for child in self.object.get_children(): - child.parent = self.object.parent - child.save() - self.object.delete() + self.object.delete(with_children=False) messages.success(request, _("Item %s was successfully deleted.") % self.object) def gen_confirm_form(self, request, message, url, singleitem=False): diff --git a/openslides/application/models.py b/openslides/application/models.py index 2c0311a85..0e0247e01 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -26,6 +26,8 @@ from utils.utils import _propper_unicode from utils.translation_ext import ugettext as _ from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote +from agenda.models import Item + class Application(models.Model, SlideMixin): prefix = "application" @@ -408,6 +410,10 @@ class Application(models.Model, SlideMixin): if self.number and not force: raise NameError('The application has already a number. ' \ 'You can not delete it.') + + + for item in Item.objects.filter(releated_sid=self.sid): + item.delete() super(Application, self).delete() def writelog(self, text, user=None): diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index a754584eb..1475db47a 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -22,6 +22,8 @@ from projector.api import register_slidemodel from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin from utils.translation_ext import ugettext as _ +from agenda.models import Item + class Assignment(models.Model, SlideMixin): prefix = 'assignment' @@ -132,6 +134,11 @@ class Assignment(models.Model, SlideMixin): def get_agenda_title(self): return self.name + def delete(self): + for item in Item.objects.filter(releated_sid=self.sid): + item.delete() + super(Assignment, self).delete() + def slide(self): """ return the slide dict