From 42ad1113fa40cf52661e81f89054255a75115d73 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 11 Jun 2013 11:14:36 +0200 Subject: [PATCH] Fixed #724 The motion updated view now uses the last_versio instead of the active_Version --- openslides/motion/forms.py | 11 +++++++---- tests/motion/test_views.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/openslides/motion/forms.py b/openslides/motion/forms.py index f5d92bb7f..2a177e7a8 100644 --- a/openslides/motion/forms.py +++ b/openslides/motion/forms.py @@ -51,13 +51,16 @@ class BaseMotionForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm): fields = () def __init__(self, *args, **kwargs): - """Fill the FormFields releated to the version data with initial data.""" + """ + Fill the FormFields releated to the version data with initial data. + """ self.motion = kwargs.get('instance', None) self.initial = kwargs.setdefault('initial', {}) if self.motion is not None: - self.initial['title'] = self.motion.title - self.initial['text'] = self.motion.text - self.initial['reason'] = self.motion.reason + last_version = self.motion.get_last_version() + self.initial['title'] = last_version.title + self.initial['text'] = last_version.text + self.initial['reason'] = last_version.reason else: self.initial['text'] = config['motion_preamble'] super(BaseMotionForm, self).__init__(*args, **kwargs) diff --git a/tests/motion/test_views.py b/tests/motion/test_views.py index c9f3e39d0..54e120d24 100644 --- a/tests/motion/test_views.py +++ b/tests/motion/test_views.py @@ -283,6 +283,22 @@ class TestMotionUpdateView(MotionViewTestCase): allow_support=False) motion.save() + def test_form_version_content(self): + """ + The content seen in the update view should be the last version + independently from the active_version. + """ + motion = Motion.objects.create(title='test', text='wrowerjlgw') + new_version = motion.get_new_version() + new_version.text = 'tpdfgojwerldkfgertdfg' + motion.save(use_version=new_version) + motion.active_version = motion.versions.all()[0] + motion.save(use_version=False) + self.assertNotEqual(motion.active_version, motion.get_last_version()) + + response = self.admin_client.get('/motion/%s/edit/' % motion.id) + self.assertEqual(response.context['form'].initial['text'], 'tpdfgojwerldkfgertdfg') + class TestMotionDeleteView(MotionViewTestCase): def test_get(self):