Prevent stopping an analog poll
Fixed too much logging with the new autoupdate bundling
This commit is contained in:
parent
90b04366b5
commit
b50cf42543
@ -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"})
|
||||||
|
|
||||||
|
@ -146,7 +146,10 @@ class RESTModelMixin:
|
|||||||
"""
|
"""
|
||||||
Returns all elements as full_data.
|
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.
|
# Get the query to receive all data from the database.
|
||||||
try:
|
try:
|
||||||
query = cls.objects.get_prefetched_queryset(ids=ids) # type: ignore
|
query = cls.objects.get_prefetched_queryset(ids=ids) # type: ignore
|
||||||
@ -167,11 +170,12 @@ 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())
|
||||||
# log progress every 5 seconds
|
if do_logging:
|
||||||
current_time = time.time()
|
# log progress every 5 seconds
|
||||||
if current_time > last_time + 5:
|
current_time = time.time()
|
||||||
last_time = current_time
|
if current_time > last_time + 5:
|
||||||
logger.info(f"\t{i+1}/{instances_length}...")
|
last_time = current_time
|
||||||
|
logger.info(f"\t{i+1}/{instances_length}...")
|
||||||
return full_data
|
return full_data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -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()
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user