#216 delete releated agenda-item, if the releated object (application or assignment) is deleted

This commit is contained in:
Oskar Hahn 2012-06-23 11:41:32 +02:00
parent d110934f62
commit 3d1e4f5489
4 changed files with 26 additions and 5 deletions

View File

@ -103,6 +103,17 @@ class Item(MPTTModel, SlideMixin):
} }
return ItemOrderForm(initial=initial, prefix="i%d" % self.id) 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'): def get_absolute_url(self, link='view'):
""" """
Return the URL to this item. By default it is the Link to its Return the URL to this item. By default it is the Link to its

View File

@ -143,13 +143,10 @@ class ItemDelete(DeleteView):
self.object = self.get_object() self.object = self.get_object()
if 'all' in request.POST: if 'all' in request.POST:
self.object.delete() self.object.delete(with_children=True)
messages.success(request, _("Item <b>%s</b> and his children were successfully deleted.") % self.object) messages.success(request, _("Item <b>%s</b> and his children were successfully deleted.") % self.object)
else: else:
for child in self.object.get_children(): self.object.delete(with_children=False)
child.parent = self.object.parent
child.save()
self.object.delete()
messages.success(request, _("Item <b>%s</b> was successfully deleted.") % self.object) messages.success(request, _("Item <b>%s</b> was successfully deleted.") % self.object)
def gen_confirm_form(self, request, message, url, singleitem=False): def gen_confirm_form(self, request, message, url, singleitem=False):

View File

@ -26,6 +26,8 @@ from utils.utils import _propper_unicode
from utils.translation_ext import ugettext as _ from utils.translation_ext import ugettext as _
from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote
from agenda.models import Item
class Application(models.Model, SlideMixin): class Application(models.Model, SlideMixin):
prefix = "application" prefix = "application"
@ -408,6 +410,10 @@ class Application(models.Model, SlideMixin):
if self.number and not force: if self.number and not force:
raise NameError('The application has already a number. ' \ raise NameError('The application has already a number. ' \
'You can not delete it.') 'You can not delete it.')
for item in Item.objects.filter(releated_sid=self.sid):
item.delete()
super(Application, self).delete() super(Application, self).delete()
def writelog(self, text, user=None): def writelog(self, text, user=None):

View File

@ -22,6 +22,8 @@ from projector.api import register_slidemodel
from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin
from utils.translation_ext import ugettext as _ from utils.translation_ext import ugettext as _
from agenda.models import Item
class Assignment(models.Model, SlideMixin): class Assignment(models.Model, SlideMixin):
prefix = 'assignment' prefix = 'assignment'
@ -132,6 +134,11 @@ class Assignment(models.Model, SlideMixin):
def get_agenda_title(self): def get_agenda_title(self):
return self.name 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): def slide(self):
""" """
return the slide dict return the slide dict