Merge pull request #1607 from normanjaeckel/PollNumber
Removed poll_number field in MotionPoll model.
This commit is contained in:
commit
026f4d45cb
19
openslides/motions/migrations/0003_auto_20150904_2029.py
Normal file
19
openslides/motions/migrations/0003_auto_20150904_2029.py
Normal 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',
|
||||||
|
),
|
||||||
|
]
|
@ -397,9 +397,7 @@ class Motion(RESTModelMixin, models.Model):
|
|||||||
Return the new poll object.
|
Return the new poll object.
|
||||||
"""
|
"""
|
||||||
if self.state.allow_create_poll:
|
if self.state.allow_create_poll:
|
||||||
# TODO: auto increment the poll_number in the database
|
poll = MotionPoll.objects.create(motion=self)
|
||||||
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.set_options()
|
poll.set_options()
|
||||||
return poll
|
return poll
|
||||||
else:
|
else:
|
||||||
@ -678,18 +676,11 @@ class MotionPoll(RESTModelMixin, CollectDefaultVotesMixin, BasePoll):
|
|||||||
ugettext_noop('Yes'), ugettext_noop('No'), ugettext_noop('Abstain')]
|
ugettext_noop('Yes'), ugettext_noop('No'), ugettext_noop('Abstain')]
|
||||||
"""The possible anwers for the poll. 'Yes, 'No' and '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):
|
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):
|
def set_options(self):
|
||||||
"""Create the option class for this poll."""
|
"""Create the option class for this poll."""
|
||||||
|
@ -61,11 +61,6 @@ class ModelTest(TestCase):
|
|||||||
self.motion.supporters.remove(self.test_user)
|
self.motion.supporters.remove(self.test_user)
|
||||||
self.assertFalse(self.motion.is_supporter(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):
|
def test_state(self):
|
||||||
self.motion.reset_state()
|
self.motion.reset_state()
|
||||||
self.assertEqual(self.motion.state.name, 'submitted')
|
self.assertEqual(self.motion.state.name, 'submitted')
|
||||||
|
Loading…
Reference in New Issue
Block a user