Merge pull request #2505 from emanuelschuetze/fix-autoupdate-for-polls

Fixed autoupdate for motion and assigment polls.
This commit is contained in:
Norman Jäckel 2016-10-12 11:34:09 +02:00 committed by GitHub
commit 1a54d1f4c6
3 changed files with 4 additions and 4 deletions

View File

@ -144,7 +144,7 @@ class AssignmentAllPollSerializer(ModelSerializer):
if vote_value not in instance.get_vote_values():
raise ValidationError({
'detail': _('Vote value %s is invalid.') % vote_value})
instance.set_vote_objects_with_values(option, votes[index])
instance.set_vote_objects_with_values(option, votes[index], skip_autoupdate=True)
# Update remaining writeable fields.
instance.description = validated_data.get('description', instance.description)

View File

@ -203,7 +203,7 @@ class MotionPollSerializer(ModelSerializer):
if vote_value not in instance.get_vote_values():
raise ValidationError({
'detail': _('Vote value %s is invalid.') % vote_value})
instance.set_vote_objects_with_values(instance.get_options().get(), votes)
instance.set_vote_objects_with_values(instance.get_options().get(), votes, skip_autoupdate=True)
# Update remaining writeable fields.
instance.votesvalid = validated_data.get('votesvalid', instance.votesvalid)

View File

@ -163,7 +163,7 @@ class BasePoll(models.Model):
"""
return self.get_vote_class().objects.filter(option__poll__id=self.id)
def set_vote_objects_with_values(self, option, data):
def set_vote_objects_with_values(self, option, data, skip_autoupdate=False):
"""
Creates or updates the vote objects for the poll.
"""
@ -173,7 +173,7 @@ class BasePoll(models.Model):
except ObjectDoesNotExist:
vote = self.get_vote_class()(option=option, value=value)
vote.weight = data[value]
vote.save()
vote.save(skip_autoupdate=skip_autoupdate)
def get_vote_objects_with_values(self, option_id):
"""