From 8743d75d106e304c52ef86c19b4ae56af22036ee Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 18 Jul 2013 09:15:16 +0200 Subject: [PATCH] Use get_active_version in motion.__unicode__() Fixes the bug, that motion.__unicode__() raises an AttributeError, if the active_version was None. Fixes #822 --- openslides/motion/models.py | 2 +- tests/motion/test_models.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/openslides/motion/models.py b/openslides/motion/models.py index fb1274094..ea2485020 100644 --- a/openslides/motion/models.py +++ b/openslides/motion/models.py @@ -100,7 +100,7 @@ class Motion(SlideMixin, models.Model): """ Return a human readable name of this motion. """ - return self.active_version.title + return self.get_active_version().title # TODO: Use transaction def save(self, use_version=None, *args, **kwargs): diff --git a/tests/motion/test_models.py b/tests/motion/test_models.py index 66f5ad13f..9db4cc796 100644 --- a/tests/motion/test_models.py +++ b/tests/motion/test_models.py @@ -146,6 +146,12 @@ class ModelTest(TestCase): motion.save(use_version=False) self.assertEqual(motion.versions.count(), 2) + def test_unicode_with_no_active_version(self): + motion = Motion.objects.create(title='foo', text='bar', identifier='') + motion.active_version = None + motion.save(update_fields=['active_version']) + self.assertEqual(str(motion), 'foo') # motion.__unicode__() did rais an AttributeError + class ConfigTest(TestCase): def test_stop_submitting(self):