diff --git a/openslides/poll/views.py b/openslides/poll/views.py index b8ab9f942..59064b398 100644 --- a/openslides/poll/views.py +++ b/openslides/poll/views.py @@ -58,6 +58,13 @@ class BasePollViewSet(ModelViewSet): @detail_route(methods=["POST"]) def stop(self, request, pk): 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: raise ValidationError({"detail": "Wrong poll state"}) diff --git a/openslides/utils/models.py b/openslides/utils/models.py index 5c4a30fa9..8a531ac17 100644 --- a/openslides/utils/models.py +++ b/openslides/utils/models.py @@ -146,7 +146,10 @@ class RESTModelMixin: """ Returns all elements as full_data. """ - logger.info(f"Loading {cls.get_collection_string()}") + do_logging = not bool(ids) + + if do_logging: + logger.info(f"Loading {cls.get_collection_string()}") # Get the query to receive all data from the database. try: query = cls.objects.get_prefetched_queryset(ids=ids) # type: ignore @@ -167,11 +170,12 @@ class RESTModelMixin: for i, instance in enumerate(instances): # Append full data from this instance full_data.append(instance.get_full_data()) - # log progress every 5 seconds - current_time = time.time() - if current_time > last_time + 5: - last_time = current_time - logger.info(f"\t{i+1}/{instances_length}...") + if do_logging: + # log progress every 5 seconds + current_time = time.time() + if current_time > last_time + 5: + last_time = current_time + logger.info(f"\t{i+1}/{instances_length}...") return full_data @classmethod diff --git a/tests/integration/assignments/test_polls.py b/tests/integration/assignments/test_polls.py index 05473ddf3..0702409c1 100644 --- a/tests/integration/assignments/test_polls.py +++ b/tests/integration/assignments/test_polls.py @@ -582,6 +582,12 @@ class VoteAssignmentPollAnalogYNA(VoteAssignmentPollBaseTestClass): self.assertEqual(poll.votescast, None) 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): self.add_candidate() self.start_poll() diff --git a/tests/integration/motions/test_polls.py b/tests/integration/motions/test_polls.py index bae17cf8e..4bbe9ef40 100644 --- a/tests/integration/motions/test_polls.py +++ b/tests/integration/motions/test_polls.py @@ -407,6 +407,12 @@ class VoteMotionPollAnalog(TestCase): self.assertEqual(poll.votescast, None) 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): self.start_poll() response = self.client.post( @@ -995,7 +1001,7 @@ class StopMotionPoll(TestCase): motion=self.motion, title="test_title_Hu9Miebopaighee3EDie", pollmethod="YNA", - type=BasePoll.TYPE_ANALOG, + type=BasePoll.TYPE_NAMED, ) self.poll.create_options()