From 4873cd71637954409b337d59693070d66b50e2b8 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 5 Aug 2012 11:28:56 +0200 Subject: [PATCH] fixted #330. Error if the related slide for an Agenda Item does not exists --- openslides/agenda/models.py | 9 ++++++++- openslides/agenda/tests.py | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index cd67de1a6..d887d553c 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -52,7 +52,14 @@ class Item(MPTTModel, SlideMixin): """ return the object, of which the item points. """ - return get_slide_from_sid(self.related_sid, True) + object = get_slide_from_sid(self.related_sid, element=True) + if object is None: + self.title = 'Item for deleted slide: %s' % self.related_sid + self.related_sid = None + self.save() + return self + else: + return object def get_related_type(self): """ diff --git a/openslides/agenda/tests.py b/openslides/agenda/tests.py index 0906eaef2..ca56e009d 100644 --- a/openslides/agenda/tests.py +++ b/openslides/agenda/tests.py @@ -15,9 +15,9 @@ from django.test.client import Client from django.contrib.auth.models import User from django.db.models.query import EmptyQuerySet -from projector.api import get_active_slide +from openslides.projector.api import get_active_slide -from agenda.models import Item +from openslides.agenda.models import Item class ItemTest(TestCase): def setUp(self): @@ -60,6 +60,10 @@ class ItemTest(TestCase): self.assertEqual(initial['parent'], 0) self.assertEqual(initial['weight'], item.weight) + def testRelated_sid(self): + self.item1.related_sid = 'foobar' + self.assertFalse(self.item1.get_related_slide() is None) + class ViewTest(TestCase): def setUp(self):