diff --git a/openslides/motions/models.py b/openslides/motions/models.py index 21d0664a4..63c26de97 100644 --- a/openslides/motions/models.py +++ b/openslides/motions/models.py @@ -50,6 +50,7 @@ class MotionManager(models.Manager): return (self.get_queryset() .select_related('active_version', 'state') .prefetch_related( + 'state__workflow', 'versions', 'agenda_items', 'log_messages', @@ -629,11 +630,10 @@ class Motion(RESTModelMixin, models.Model): raise WorkflowError('You can not create a poll in state %s.' % self.state.name) @property - def workflow(self): + def workflow_id(self): """ Returns the id of the workflow of the motion. """ - # TODO: Rename to workflow_id return self.state.workflow.pk def set_state(self, state): diff --git a/openslides/motions/serializers.py b/openslides/motions/serializers.py index 9bd019c1b..51692cc3b 100644 --- a/openslides/motions/serializers.py +++ b/openslides/motions/serializers.py @@ -369,8 +369,7 @@ class MotionSerializer(ModelSerializer): workflow_id = IntegerField( min_value=1, required=False, - validators=[validate_workflow_field], - write_only=True) + validators=[validate_workflow_field]) agenda_type = IntegerField(write_only=True, required=False, min_value=1, max_value=3) agenda_parent_id = IntegerField(write_only=True, required=False, min_value=1) submitters = SubmitterSerializer(many=True, read_only=True) @@ -475,7 +474,7 @@ class MotionSerializer(ModelSerializer): # Workflow. workflow_id = validated_data.get('workflow_id') - if workflow_id is not None and workflow_id != motion.workflow: + if workflow_id is not None and workflow_id != motion.workflow_id: motion.reset_state(workflow_id) # Decide if a new version is saved to the database. diff --git a/openslides/motions/views.py b/openslides/motions/views.py index f43970ee4..a8e026986 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -557,7 +557,7 @@ class MotionViewSet(ModelViewSet): recommendation_state_id = int(recommendation_state) except ValueError: raise ValidationError({'detail': _('Invalid data. Recommendation must be an integer.')}) - recommendable_states = State.objects.filter(workflow=motion.workflow, recommendation_label__isnull=False) + recommendable_states = State.objects.filter(workflow=motion.workflow_id, recommendation_label__isnull=False) if recommendation_state_id not in [item.id for item in recommendable_states]: raise ValidationError( {'detail': _('You can not set the recommendation to {recommendation_state_id}.').format( diff --git a/tests/integration/motions/test_viewset.py b/tests/integration/motions/test_viewset.py index c15a10759..26e8bf13a 100644 --- a/tests/integration/motions/test_viewset.py +++ b/tests/integration/motions/test_viewset.py @@ -30,6 +30,7 @@ def test_motion_db_queries(): """ Tests that only the following db queries are done: * 1 requests to get the list of all motions, + * 1 request to get the associated workflow * 1 request to get the motion versions, * 1 request to get the agenda item, * 1 request to get the motion log, @@ -45,7 +46,7 @@ def test_motion_db_queries(): password='password') # TODO: Create some polls etc. - assert count_queries(Motion.get_elements) == 9 + assert count_queries(Motion.get_elements) == 10 @pytest.mark.django_db(transaction=False) @@ -436,7 +437,7 @@ class UpdateMotion(TestCase): motion = Motion.objects.get() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh') - self.assertEqual(motion.workflow, 2) + self.assertEqual(motion.workflow_id, 2) def test_patch_supporters(self): supporter = get_user_model().objects.create_user(