fixed motion tests
This commit is contained in:
parent
ef7f6cf476
commit
cbd4acbd4b
@ -90,7 +90,11 @@ class Motion(SlideMixin, models.Model):
|
|||||||
self.reset_state()
|
self.reset_state()
|
||||||
|
|
||||||
super(Motion, self).save(*args, **kwargs)
|
super(Motion, self).save(*args, **kwargs)
|
||||||
|
# Find out if the version data has changed
|
||||||
for attr in ['title', 'text', 'reason']:
|
for attr in ['title', 'text', 'reason']:
|
||||||
|
if not self.versions.exists():
|
||||||
|
new_data = True
|
||||||
|
break
|
||||||
if getattr(self, attr) != getattr(self.last_version, attr):
|
if getattr(self, attr) != getattr(self.last_version, attr):
|
||||||
new_data = True
|
new_data = True
|
||||||
break
|
break
|
||||||
@ -103,27 +107,31 @@ class Motion(SlideMixin, models.Model):
|
|||||||
del self._new_version
|
del self._new_version
|
||||||
version.motion = self # Test if this line is realy neccessary.
|
version.motion = self # Test if this line is realy neccessary.
|
||||||
elif new_data and not need_new_version:
|
elif new_data and not need_new_version:
|
||||||
# TODO: choose an explicit version
|
|
||||||
version = self.last_version
|
version = self.last_version
|
||||||
else:
|
else:
|
||||||
# We do not need to save the motion version
|
# We do not need to save the motion version
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Save title, text and reason in the version object
|
||||||
for attr in ['title', 'text', 'reason']:
|
for attr in ['title', 'text', 'reason']:
|
||||||
_attr = '_%s' % attr
|
_attr = '_%s' % attr
|
||||||
try:
|
try:
|
||||||
setattr(version, attr, getattr(self, _attr))
|
setattr(version, attr, getattr(self, _attr))
|
||||||
delattr(self, _attr)
|
delattr(self, _attr)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
if self.versions.exists():
|
||||||
# If the _attr was not set, use the value from last_version
|
# If the _attr was not set, use the value from last_version
|
||||||
setattr(version, attr, getattr(self.last_version, attr))
|
setattr(version, attr, getattr(self.last_version, attr))
|
||||||
|
|
||||||
|
# Set version_number of the new Version (if neccessary) and save it into the DB
|
||||||
if version.id is None:
|
if version.id is None:
|
||||||
# TODO: auto increment the version_number in the Database
|
# TODO: auto increment the version_number in the Database
|
||||||
version_number = self.versions.aggregate(Max('version_number'))['version_number__max'] or 0
|
version_number = self.versions.aggregate(Max('version_number'))['version_number__max'] or 0
|
||||||
version.version_number = version_number + 1
|
version.version_number = version_number + 1
|
||||||
version.save()
|
version.save()
|
||||||
|
|
||||||
|
# Set the active Version of this motion. This has to be done after the
|
||||||
|
# version is saved to the db
|
||||||
if not self.state.version_permission or self.active_version is None:
|
if not self.state.version_permission or self.active_version is None:
|
||||||
self.active_version = version
|
self.active_version = version
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -65,7 +65,7 @@ class ModelTest(TestCase):
|
|||||||
self._title
|
self._title
|
||||||
self.assertEqual(motion.title, 'v3')
|
self.assertEqual(motion.title, 'v3')
|
||||||
|
|
||||||
motion.version = 0
|
motion.version = 1
|
||||||
self.assertEqual(motion.title, 'v1')
|
self.assertEqual(motion.title, 'v1')
|
||||||
|
|
||||||
motion.version = v2_version
|
motion.version = v2_version
|
||||||
|
Loading…
Reference in New Issue
Block a user