2016-03-02 00:46:19 +01:00
|
|
|
from openslides.utils.rest_api import ModelSerializer, RelatedField
|
2015-01-24 16:35:50 +01:00
|
|
|
|
2015-01-06 00:14:49 +01:00
|
|
|
from .models import Item, Speaker
|
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class SpeakerSerializer(ModelSerializer):
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2015-01-17 14:25:05 +01:00
|
|
|
Serializer for agenda.models.Speaker objects.
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Speaker
|
|
|
|
fields = (
|
|
|
|
'id',
|
|
|
|
'user',
|
|
|
|
'begin_time',
|
|
|
|
'end_time',
|
2015-07-06 09:19:42 +02:00
|
|
|
'weight',
|
2018-02-06 14:52:47 +01:00
|
|
|
'marked',
|
2015-07-06 09:19:42 +02:00
|
|
|
'item', # js-data needs the item-id in the nested object to define relations.
|
|
|
|
)
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class RelatedItemRelatedField(RelatedField):
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
2015-02-04 00:08:38 +01:00
|
|
|
A custom field to use for the content_object generic relationship.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
|
|
|
def to_representation(self, value):
|
|
|
|
"""
|
2015-02-04 00:08:38 +01:00
|
|
|
Returns info concerning the related object extracted from the api URL
|
|
|
|
of this object.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
2016-03-02 00:46:19 +01:00
|
|
|
return {'collection': value.get_collection_string(), 'id': value.get_rest_pk()}
|
2015-01-17 14:25:05 +01:00
|
|
|
|
|
|
|
|
2015-02-12 18:48:14 +01:00
|
|
|
class ItemSerializer(ModelSerializer):
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2015-01-17 14:25:05 +01:00
|
|
|
Serializer for agenda.models.Item objects.
|
2015-01-06 00:14:49 +01:00
|
|
|
"""
|
2015-01-17 14:25:05 +01:00
|
|
|
content_object = RelatedItemRelatedField(read_only=True)
|
2015-07-06 09:19:42 +02:00
|
|
|
speakers = SpeakerSerializer(many=True, read_only=True)
|
2015-01-06 00:14:49 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
2015-01-24 16:35:50 +01:00
|
|
|
fields = (
|
2015-02-04 00:08:38 +01:00
|
|
|
'id',
|
2015-01-24 16:35:50 +01:00
|
|
|
'item_number',
|
|
|
|
'title',
|
2016-01-25 21:22:22 +01:00
|
|
|
'list_view_title',
|
2015-01-24 16:35:50 +01:00
|
|
|
'comment',
|
|
|
|
'closed',
|
|
|
|
'type',
|
2016-01-09 16:24:37 +01:00
|
|
|
'is_hidden',
|
2015-01-24 16:35:50 +01:00
|
|
|
'duration',
|
2015-07-06 09:19:42 +02:00
|
|
|
'speakers',
|
2015-01-24 16:35:50 +01:00
|
|
|
'speaker_list_closed',
|
|
|
|
'content_object',
|
2015-09-06 14:02:15 +02:00
|
|
|
'weight',
|
|
|
|
'parent',)
|