The motion updated view now uses the last_versio instead of the active_Version
This commit is contained in:
Oskar Hahn 2013-06-11 11:14:36 +02:00
parent 097d369c89
commit 42ad1113fa
2 changed files with 23 additions and 4 deletions

View File

@ -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)

View File

@ -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):