Merge pull request #1607 from normanjaeckel/PollNumber

Removed poll_number field in MotionPoll model.
This commit is contained in:
Oskar Hahn 2015-09-05 09:58:57 +02:00
commit 026f4d45cb
3 changed files with 24 additions and 19 deletions

View File

@ -0,0 +1,19 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('motions', '0002_auto_20150904_1448'),
]
operations = [
migrations.AlterUniqueTogether(
name='motionpoll',
unique_together=set([]),
),
migrations.RemoveField(
model_name='motionpoll',
name='poll_number',
),
]

View File

@ -397,9 +397,7 @@ class Motion(RESTModelMixin, models.Model):
Return the new poll object.
"""
if self.state.allow_create_poll:
# TODO: auto increment the poll_number in the database
poll_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
poll = MotionPoll.objects.create(motion=self)
poll.set_options()
return poll
else:
@ -678,18 +676,11 @@ class MotionPoll(RESTModelMixin, CollectDefaultVotesMixin, BasePoll):
ugettext_noop('Yes'), ugettext_noop('No'), ugettext_noop('Abstain')]
"""The possible anwers for the poll. 'Yes, 'No' and 'Abstain'."""
poll_number = models.PositiveIntegerField(default=1)
"""An id for this poll in realation to a motion.
Is unique for each motion.
"""
class Meta:
unique_together = ("motion", "poll_number")
def __str__(self):
"""Return a string, representing the poll."""
return _('Vote %d') % self.poll_number
"""
Representation method only for debugging purposes.
"""
return 'MotionPoll for motion %s' % self.motion
def set_options(self):
"""Create the option class for this poll."""

View File

@ -61,11 +61,6 @@ class ModelTest(TestCase):
self.motion.supporters.remove(self.test_user)
self.assertFalse(self.motion.is_supporter(self.test_user))
def test_poll(self):
self.motion.state = State.objects.get(pk=1)
poll = self.motion.create_poll()
self.assertEqual(poll.poll_number, 1)
def test_state(self):
self.motion.reset_state()
self.assertEqual(self.motion.state.name, 'submitted')