Only save new version, when version-data has changed

This commit is contained in:
Oskar Hahn 2013-01-26 15:39:35 +01:00
parent 1f87749742
commit 8708ba5da6
3 changed files with 5 additions and 9 deletions

View File

@ -49,8 +49,6 @@ class MotionSupporterMixin(forms.ModelForm):
supporter = MultiplePersonFormField(required=False, label=_("Supporters")) supporter = MultiplePersonFormField(required=False, label=_("Supporters"))
class MotionTrivialChangesMixin(object): class MotionTrivialChangesMixin(object):
trivial_change = forms.BooleanField( trivial_change = forms.BooleanField(
required=False, label=_("Trivial change"), required=False, label=_("Trivial change"),

View File

@ -87,11 +87,13 @@ class Motion(SlideMixin, models.Model):
Saves the motion. Create or update a motion_version object Saves the motion. Create or update a motion_version object
""" """
super(Motion, self).save(*args, **kwargs) super(Motion, self).save(*args, **kwargs)
new_data = False for attr in ['title', 'text', 'reason']:
for attr in ['_title', '_text', '_reason']: if getattr(self, attr) != getattr(self.last_version, attr):
if hasattr(self, attr):
new_data = True new_data = True
break break
else:
new_data = False
need_new_version = True # TODO: Do we need a new version (look in config) need_new_version = True # TODO: Do we need a new version (look in config)
if hasattr(self, '_version') or (new_data and need_new_version): if hasattr(self, '_version') or (new_data and need_new_version):
version = self.new_version version = self.new_version

View File

@ -32,10 +32,6 @@ from .models import Motion, MotionSubmitter
from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin, from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin,
MotionTrivialChangesMixin) MotionTrivialChangesMixin)
from django.views.generic.edit import ModelFormMixin
class MotionListView(ListView): class MotionListView(ListView):
""" """
List all motion. List all motion.