commit
5d122d1d27
@ -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)
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user