2015-02-12 18:48:14 +01:00
|
|
|
from openslides.utils.rest_api import ModelSerializer, PrimaryKeyRelatedField, SerializerMethodField
|
2015-01-24 16:35:50 +01:00
|
|
|
|
|
|
|
from .models import (
|
|
|
|
Category,
|
|
|
|
Motion,
|
|
|
|
MotionLog,
|
|
|
|
MotionOption,
|
|
|
|
MotionPoll,
|
|
|
|
MotionSubmitter,
|
|
|
|
MotionSupporter,
|
|
|
|
MotionVersion,
|
|
|
|
MotionVote,
|
|
|
|
State,
|
|
|
|
Workflow,)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class CategorySerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.Category objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Category
|
2015-02-04 00:08:38 +01:00
|
|
|
fields = ('id', 'name', 'prefix',)
|
2015-01-24 16:35:50 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class StateSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.State objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = State
|
|
|
|
fields = (
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'action_word',
|
|
|
|
'icon',
|
|
|
|
'required_permission_to_see',
|
|
|
|
'allow_support',
|
|
|
|
'allow_create_poll',
|
|
|
|
'allow_submitter_edit',
|
|
|
|
'versioning',
|
|
|
|
'leave_old_version_active',
|
|
|
|
'dont_set_identifier',
|
|
|
|
'next_states',)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class WorkflowSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.Workflow objects.
|
|
|
|
"""
|
|
|
|
state_set = StateSerializer(many=True, read_only=True)
|
2015-02-12 18:48:14 +01:00
|
|
|
first_state = PrimaryKeyRelatedField(read_only=True)
|
2015-01-24 16:35:50 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Workflow
|
2015-02-04 00:08:38 +01:00
|
|
|
fields = ('id', 'name', 'state_set', 'first_state',)
|
2015-01-24 16:35:50 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionSubmitterSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionSubmitter objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = MotionSubmitter
|
|
|
|
fields = ('person',) # TODO: Rename this to 'user', see #1348
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionSupporterSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionSupporter objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = MotionSupporter
|
|
|
|
fields = ('person',) # TODO: Rename this to 'user', see #1348
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionLogSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionLog objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = MotionLog
|
|
|
|
fields = ('message_list', 'person', 'time',)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionVoteSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionVote objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = MotionVote
|
|
|
|
fields = ('value', 'weight',)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionOptionSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionOption objects.
|
|
|
|
"""
|
|
|
|
motionvote_set = MotionVoteSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MotionOption
|
|
|
|
fields = ('motionvote_set',)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionPollSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionPoll objects.
|
|
|
|
"""
|
|
|
|
motionoption_set = MotionOptionSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MotionPoll
|
|
|
|
fields = (
|
|
|
|
'poll_number',
|
|
|
|
'motionoption_set',
|
|
|
|
'votesvalid',
|
|
|
|
'votesinvalid',
|
|
|
|
'votescast',)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionVersionSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.MotionVersion objects.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = MotionVersion
|
|
|
|
fields = (
|
|
|
|
'id',
|
|
|
|
'version_number',
|
|
|
|
'creation_time',
|
|
|
|
'title',
|
|
|
|
'text',
|
|
|
|
'reason',)
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class MotionSerializer(ModelSerializer):
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
|
|
|
Serializer for motion.models.Motion objects.
|
|
|
|
"""
|
|
|
|
versions = MotionVersionSerializer(many=True, read_only=True)
|
2015-02-12 18:48:14 +01:00
|
|
|
active_version = PrimaryKeyRelatedField(read_only=True)
|
2015-01-24 16:35:50 +01:00
|
|
|
submitter = MotionSubmitterSerializer(many=True, read_only=True)
|
|
|
|
supporter = MotionSupporterSerializer(many=True, read_only=True)
|
|
|
|
state = StateSerializer(read_only=True)
|
2015-02-12 18:48:14 +01:00
|
|
|
workflow = SerializerMethodField()
|
2015-01-24 16:35:50 +01:00
|
|
|
polls = MotionPollSerializer(many=True, read_only=True)
|
|
|
|
log_messages = MotionLogSerializer(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Motion
|
|
|
|
fields = (
|
2015-02-04 00:08:38 +01:00
|
|
|
'id',
|
2015-01-24 16:35:50 +01:00
|
|
|
'identifier',
|
|
|
|
'identifier_number',
|
|
|
|
'parent',
|
|
|
|
'category',
|
|
|
|
'tags',
|
|
|
|
'versions',
|
|
|
|
'active_version',
|
|
|
|
'submitter',
|
|
|
|
'supporter',
|
|
|
|
'state',
|
|
|
|
'workflow',
|
|
|
|
'attachments',
|
|
|
|
'polls',
|
|
|
|
'log_messages',)
|
|
|
|
|
|
|
|
def get_workflow(self, motion):
|
|
|
|
"""
|
2015-02-04 00:08:38 +01:00
|
|
|
Returns the id of the workflow of the motion.
|
2015-01-24 16:35:50 +01:00
|
|
|
"""
|
2015-02-04 00:08:38 +01:00
|
|
|
return motion.state.workflow.pk
|