Prevent stopping an analog poll

Fixed too much logging with the new autoupdate bundling
This commit is contained in:
FinnStutzenstein 2019-11-13 07:46:13 +01:00
parent 90b04366b5
commit b50cf42543
4 changed files with 30 additions and 7 deletions

View File

@ -58,6 +58,13 @@ class BasePollViewSet(ModelViewSet):
@detail_route(methods=["POST"]) @detail_route(methods=["POST"])
def stop(self, request, pk): def stop(self, request, pk):
poll = self.get_object() poll = self.get_object()
# Analog polls could not be stopped; they are stopped when
# the results are entered.
if poll.type == BasePoll.TYPE_ANALOG:
raise ValidationError(
{"detail": "Analog polls can not be stopped. Please enter votes."}
)
if poll.state != BasePoll.STATE_STARTED: if poll.state != BasePoll.STATE_STARTED:
raise ValidationError({"detail": "Wrong poll state"}) raise ValidationError({"detail": "Wrong poll state"})

View File

@ -146,6 +146,9 @@ class RESTModelMixin:
""" """
Returns all elements as full_data. Returns all elements as full_data.
""" """
do_logging = not bool(ids)
if do_logging:
logger.info(f"Loading {cls.get_collection_string()}") logger.info(f"Loading {cls.get_collection_string()}")
# Get the query to receive all data from the database. # Get the query to receive all data from the database.
try: try:
@ -167,6 +170,7 @@ class RESTModelMixin:
for i, instance in enumerate(instances): for i, instance in enumerate(instances):
# Append full data from this instance # Append full data from this instance
full_data.append(instance.get_full_data()) full_data.append(instance.get_full_data())
if do_logging:
# log progress every 5 seconds # log progress every 5 seconds
current_time = time.time() current_time = time.time()
if current_time > last_time + 5: if current_time > last_time + 5:

View File

@ -582,6 +582,12 @@ class VoteAssignmentPollAnalogYNA(VoteAssignmentPollBaseTestClass):
self.assertEqual(poll.votescast, None) self.assertEqual(poll.votescast, None)
self.assertFalse(poll.get_votes().exists()) self.assertFalse(poll.get_votes().exists())
def test_stop_poll(self):
self.start_poll()
response = self.client.post(reverse("assignmentpoll-stop", args=[self.poll.pk]))
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(self.poll.state, AssignmentPoll.STATE_STARTED)
def test_vote(self): def test_vote(self):
self.add_candidate() self.add_candidate()
self.start_poll() self.start_poll()

View File

@ -407,6 +407,12 @@ class VoteMotionPollAnalog(TestCase):
self.assertEqual(poll.votescast, None) self.assertEqual(poll.votescast, None)
self.assertFalse(poll.get_votes().exists()) self.assertFalse(poll.get_votes().exists())
def test_stop_poll(self):
self.start_poll()
response = self.client.post(reverse("motionpoll-stop", args=[self.poll.pk]))
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(self.poll.state, MotionPoll.STATE_STARTED)
def test_vote(self): def test_vote(self):
self.start_poll() self.start_poll()
response = self.client.post( response = self.client.post(
@ -995,7 +1001,7 @@ class StopMotionPoll(TestCase):
motion=self.motion, motion=self.motion,
title="test_title_Hu9Miebopaighee3EDie", title="test_title_Hu9Miebopaighee3EDie",
pollmethod="YNA", pollmethod="YNA",
type=BasePoll.TYPE_ANALOG, type=BasePoll.TYPE_NAMED,
) )
self.poll.create_options() self.poll.create_options()